Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERC-20 Approve function fails with "Internal JSON-RPC error" #53

Open
maximvhs opened this issue Feb 11, 2025 · 4 comments
Open

ERC-20 Approve function fails with "Internal JSON-RPC error" #53

maximvhs opened this issue Feb 11, 2025 · 4 comments

Comments

@maximvhs
Copy link

Hello,

I'm having an issue with calling the approve function on an ERC20 contract. I'm using Metamask wallet

Code:

var chain = new GameChain() {
                    id = 13337,
                    eip = "eip155:13337",
                    name = "Beam Testnet",
                    symbol = "Beam",
                    decimals = 18,
                    rpcAddress = "https://build.onbeam.com/rpc/testnet",
                    scanName = "Beam Testnet Block Explorer",
                    scanAddress = "https://subnets-test.avax.network/beam",
                    imageUrl = "...",
                    isTestnet = true
};

var reownChain = new Chain(ChainConstants.Namespaces.Evm,
    chain.id.ToString(),
    chain.name,
    new Currency(chain.symbol, chain.symbol.ToUpper(), chain.decimals),
    new BlockExplorer(chain.scanName, chain.scanAddress),
    chain.rpcAddress,
    chain.isTestnet,
    chain.imageUrl);

var supportedChains = new List<Chain>();
supportedChains.Add(reownChain);

var appKitConfig = new AppKitConfig("...", metadata)
{
    supportedChains = supportedChains.ToArray()
};

await AppKit.InitializeAsync(appKitConfig);

...

var gasAmount = await AppKit.Evm.EstimateGasAsync(contractAddress, contractAbi, "approve", default, spenderAddress, costInWei);
response = await AppKit.Evm.WriteContractAsync(contractAddress, contractAbi, "approve", gasAmount, spenderAddress, costInWei);

Contract ABI:

[{"type":"function","name":"balanceOf","inputs":[{"name":"account","type":"address"}],"outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view"},{"type":"function","name":"approve","inputs":[{"name":"spender","type":"address"},{"name":"amount","type":"uint256"}],"outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable"}]

EstimateGasAsync call results in this error

RpcResponseException: execution reverted: ERC20: approve from the zero address: eth_estimateGas

not sure how to specify the from address

If I just call WriteContractAsync without EstimateGas I get this

Internal JSON-RPC error
@skibitsky
Copy link
Member

Hello!

Is that on webgl or native/unity editor?

@maximvhs
Copy link
Author

Hi, Unity editor and windows build

@skibitsky
Copy link
Member

skibitsky commented Feb 12, 2025

This is an internal MetaMask error, our sdk receives that error message from MetaMask and just throws it as an exception. Could you check if your Beam Testnet network is configured correctly in MetaMask app and you have enough gas tokens?

Relevant MetaMask docs:
https://support.metamask.io/configure/networks/error-internal-json-rpc-error-when-trying-to-interact-with-other-networks/

@maximvhs
Copy link
Author

Thank you for help, when I manually entered a high enough gas limit in metamask for the approve function, it worked.

But this error still remains

RpcResponseException: execution reverted: ERC20: approve from the zero address: eth_estimateGas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants