Ethereum Unity3D Boilerplate Questions

hey, to send a custom token, you need to have the contract abi in your code, take a look at this
(https://github.com/0xPr0f/Moralis-Unity/blob/master/Assets/SendCustomToken.cs) this was a template i made.
you can also read down from here to see how it is done and the parameters
(https://github.com/ethereum-boilerplate/ethereum-unity-boilerplate#web3)

1 Like

Thank you ! this helped me a lot !
However, when I try to confirm the payement with imtoken wallet, it keeps saying “network is busy, please try again later”. On metamask it says “internal JSON-RPC error” and on trust wallet it says nothing.
any idea where this might come from ?

Thanks again !

1 Like

Also, is it the same function for sending nfts?

I would need to be able to exchange an Erc20 for an erc1155 minted nft between two accounts.
Security wise, how can I be sure both transactions happen at the same time ?

Thanks again !

hey, for imtoken, it could be the wallet or network specifically
for metamask, did you set the wallet connection to metamask? and did you set the chain id ?
for wallet connect too, did you set the chainid ?

and that code sample allows you to call a contract function, it can be anything as long as it is a function in the contract abi so, it isnt specific (you can use it to call a smart contract function)

1 Like

Hello im new here and I have a noob question, … So I logged in succesfuly using the wallet connect QR code … I have the wallet address displaying on the screen but how do I display certain nfts from the wallet onto a canvas image … thanks for the help … !

1 Like

you can use the getnft web3api method for that
(https://github.com/ethereum-boilerplate/ethereum-unity-boilerplate#getnfts)
take a look at this in practical usage
(https://github.com/0xPr0f/Moralis-Unity/blob/master/README.md)
then you have to get the image and then render it on a image object in unity
this is an example in more complex code
(https://github.com/0xPr0f/chillHouse/blob/9cf6e3c19676fdf121e55fa14e7341f929c59ab2/Assets/Script/CovelentData.cs#L209)
here, the image is been rendered

2 Likes

hey bro thanks for answering … going to check it out right now . .any questions I will get back to you … cheers my man !

Hi @dgoodrich

Regarding this: https://github.com/ethereum-boilerplate/ethereum-unity-boilerplate/issues/32#issue-1119418735

What is ETA for merging in-Browser Wallet for WebGL in the main release?

1 Like

For Metamask, I have set the wallet connection to metamask and the chain ID is always Mumbai 80001 but it still shows error “internal JSON-RPC error” but in the error log in unity I found that I might have missused the SendTransactionAsync function.

This is my code:

public async void SendToken()
    {
        MoralisInterface.InsertContractInstance("AKT", ABI, "mumbai", tokenAddress);
        Function f = MoralisInterface.EvmContractFunctionInstance("AKT", "mumbai", "transfer");
        string jsonresult = await f.SendTransactionAsync(senderAccount, receiverAccount, 100000000000000000);
        print(jsonresult);
        
    }

My transfer function in the smart contract takes in only a receiver address and an amount. the solidity code is here:

function transfer(address receiver, uint256 numTokens) public override returns (bool) {
        require(numTokens <= balances[msg.sender]);
        balances[msg.sender] = balances[msg.sender].sub(numTokens);
        balances[receiver] = balances[receiver].add(numTokens);
        emit Transfer(msg.sender, receiver, numTokens);
        return true;
    }

Thank you very much for your help and support.
Best

Did you set the chainId as that in the wallet connect option ? It shouldn’t return this error :thinking:

Yes I did!

And this is the unity log from this error. The P2P transaction script L.125 corresponds to this line:

string jsonresult = await f.SendTransactionAsync(senderAccount, receiverAccount, 100000000000000000);

Thanks a lot !

1 Like

that drop down that says trust is supposed to be metamask in the defualt wallet option, :thinking: this is weird, let me test this and get back to you

1 Like

I know sorry that was the wrong screenshot!
I have tried it with metamask when I use metamask, and trust wallet when I used trust wallet .
(Although for authentification that dropdown doesn’t seem to change anything :slight_smile: )

1 Like

@Hero909 and @0xprof the transfer of a NFT is a contract call - see the AwardableController.cs in the boilerplate for an example.

@will1 and @0xprof As 0xprof said use web3Api to load the NFT information and then use the image URL in the response to load the image data.

To render the data you need to load it into a Texture2D. Unity does not support loading GIFs programmatically so if the image is a GIF use the GifDecoder library I included with the boilerplate.

1 Like

I will be posting a pre-release package with this later today.

Is there any news about Metamask Interface for WebGL?

1 Like

Thanks a lot @dgoodrich for the details, I will dig into all of this for sure ! Thanks again !

Do you have any idea why the ERC20 transfer fails on metamask, trust wallet and imtoken ? it says “internal JSON-RPC error”

1 Like

thanks for sharing … This questions is probably dumb but here goes anyways … when you mean GIF do you mean all image formats or just “GIF” … is it able to load pngs or jpegs automatically ? and thanks again !

1 Like