1

Hey i have to build a ERC20 contract and using alchemy sdk to send transactions onchain For eg mint or burn tokens. But i am not able to send a transaction as its showing an error of cannot estimate gas

const API_KEY = process.env.API_KEY;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;

// provider - Alchemy
const alchemyProvider = new ethers.providers.AlchemyProvider(network="maticmum", API_KEY);

// signer - you
const signer = new ethers.Wallet(PRIVATE_KEY, alchemyProvider);

// contract instance
const helloWorldContract = new ethers.Contract(CONTRACT_ADDRESS, ABI, signer);

async function main() {
    // console.log(helloWorldContract);
    const message = await helloWorldContract.symbol();
    console.log("The message is: " + message); 
    
    const a=await signer.getGasPrice()
    console.log(a.toString());
    
    console.log("Updating the message...");
    const tx = await helloWorldContract.mint(100);
    await tx.wait();
    
    // const message2 = await helloWorldContract.balanceOf(CONTRACT_ADDRESS);
    // console.log("The message is: " + message2); 
}

main();

And the error i am facing is

var error = new Error(message);
                    ^

<ref *1> Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"cannot estimate gas; transaction may fail or may require manual gas limit","code":"UNPREDICTABLE_GAS_LIMIT"

I have gone through docs but cannot find the reason.

Chain used - Polygon_mumbai

Or if there is any other method/framework that can do this other than this sdk, please recommend

1 Answer 1

0

Try out web3client.app

Here is the link to download erc20 directly and you can execute it.

It uses ethers default provider to execute the transaction. Try the code feature to get the working code you are looking for.

This might help you i believe.

Alternatively, you can try hardhat to deploy contract locally before pushing it to prod

Here is a small tutorial for it.

2
  • 1
    Thanks,@sam but here my mistake was that i din't had enough MATIC on my wallet. So after adding more MATIC it worked fine for me. Feb 25, 2023 at 21:56
  • Ok ok got it ✌️
    – sam
    Feb 27, 2023 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.