Iām not trying to deploy a contract, Iām trying to perform a transaction.
In my frontend, is there anywhere for me to specify chainID? (incase itās something to do with that)
Iām not trying to deploy a contract, Iām trying to perform a transaction.
In my frontend, is there anywhere for me to specify chainID? (incase itās something to do with that)
you select the network in metamask and the frontend should use the chain/network that is selected in metamask
I tried doing it on Goerli and I got an unhandled runtime error which usually means gas estimation failed. It definitely has something to do with gas.
When I run it on Hardhat, I specify gasLimit like this:
tx = await wf.connect(creator).createClone({
value: ethers.utils.parseUnits("1000000000000000", "wei"),
gasLimit: 6000000,
})
As of now, Iām specifying gas limit like this in the front end:
onClick={createInstance == true ? async function () {
await createClone({
onSuccess: handleSuccess,
onError: (error) => console.log(error),
gasLimit: 6000000,
});
Is this the correct with to specify gasLimit?
I am not sure about that syntax, when it works in hardhat, what is the total gas cost for that transaction?
gas cost is 0.09 Matic. Iām pretty sure the issue is I have to explicitly mention the gasLimit. I remember this failing on hardhat as well until I mentioned the gasLimit.
can you also try to specify the gas cost?
Iāve tried, it didnāt work. Is there a way to use ethers syntax?
you can use ethers syntax directly, you donāt have to use uweWeb3Contract
and how do I make that work with a button? Do I put that all inside a const?
Iām not expert in react, I guess that you add a callback function to a button and you call it
One more question, what provider do I use if Iām using ConnectButton from web3uikit?
I donāt know this, there has to be a way to get access to ethers provider, like ethers = await Moralis.enableWeb3()
was the syntax in vanilla js
Hey @cryptokid,
I turned on āmanual gas limitā in advanced settings of metamask and when I set it to 6000000 the function worked. However, now Iām wondering how to do this via Moralis. I know you said I could use ethers directly, and I looked at the web3provider section of the docs, however that gave me some errors. This was my code:
const create = async function () {
address = ā<address>ā
const ethers = Moralis.web3Library;
const web3Provider = await Moralis.enableWeb3();
const gasPrice = await web3Provider.getGasPrice();
const signer = web3Provider.getSigner();
const contract = new ethers.Contract(address, whoopyAbi, signer);
const transaction = await contract.deposit({
value: Moralis.Units.ETH('1'),
gasLimit: 100000000,
gasPrice: gasPrice,
});
await transaction.wait();
}
When I use this, I get the invalid address or ENS name error.
Do you have any recommendations on how I can go about this?
Thanks!
Is your wallet on the right chain for that contract? And doublecheck all your parameters - address, ABI, function name (deposit).
Itās working now! I switched some stuff around but am using the exact same syntax as above. I have a tiny issue though. How can I call the onSuccess and onError params as they arenāt working with my const function?
I got it, I just added the handleSuccess function at the end of the create function. Thanks guys! @alex @cryptokid
Hello Tom,
I ran into the same issue āexceeds block gas limitā for useWeb3Contract only on mumbai but calling the same contract functions works perfectly fine on front end in localhost and in hardhat. I also noticed that only functions that change state are giving issues as view functions work fine. What was the solution that you used to resolve this?
Thanks,
Hey,
Yes, itās only functions that change state which give issue. Even mine worked fine on hardhat but didnāt work on Mumbai.
The solution is to use ethers directly instead of useWeb3Contract and to specify a gasLimit of 6000000. The syntax is this:
const create = async function () {
address = "<address>"
const ethers = Moralis.web3Library;
const web3Provider = await Moralis.enableWeb3();
const gasPrice = await web3Provider.getGasPrice();
const signer = web3Provider.getSigner();
const contract = new ethers.Contract(address, ABI, signer);
const transaction = await contract.createClone({
value: ethers.utils.parseUnits("1000000000000000", "wei"),
gasLimit: 6000000,
gasPrice: gasPrice,
});
await transaction.wait(3);
await handleSuccess(transaction)
}
You can also check this out: https://v1docs.moralis.io/moralis-dapp/web3/web3
hey facing similar issue, can u share how u fixed it?
Hey @tomwhiteman
I just wanted to let you know that Iāve been working on the same issue for the past two days, and your code helped me solve the problem. Iām forever grateful!