Setting value on deploy

Hi guys, I am using web3.js to deploy a contract. I am using the following code:

const standardtokenContract = new web3.eth.Contract(abi);
            standardtokenContract.
                deploy({
                    data: '0x' + bytecode,
                    arguments: [
                        $name_,
                        $symbol_,
                        $decimalUnits,
                        $initialSupply_,
                        feeReceiver_],
                    })
                .send({
                    from: userAddress,
		   value: web3.utils.toWei('5')
                  })

When I deploy the contract without the value parameter it deploys just fine. The problem is that when I introduce the value, the gas fee increases a lot (from around 70$ to 1000$ in eth). I have deployed the same contract using the value parameter on Remix with the gas fee remaining constant or just increasing for a couple of dollars. That is why I know it is not an smart contract issue, but something regarding the js.

The contract deploys nicely using js when I delete the value parameter, so I am guessing the problem may be with the web3.utilstoWei() implementation. What do you think? Why is the gas fee increasing tremendously when I include a value?

I am using the bytecode and ABI from Remix and the web3.js version is 1.2.8.

Any help would be much appreciated,
Thank you and best regards,
Íñigo

Hi,

Did you try to deploy on a testnet?
That total gas price value is from the gas price or from how much gas is used?

That value parameter that is only 5 in this case, it shouldn’t be related to gas cost.

You could get a huge gas estimation if the node can not estimate what would be the gas cost for that deploy (not the gas price).

I have tried on a testnet and the same thing happens. I am refering to the estimated gas fee by Metamask. I do not understand why it gets so high, jut by including the value.

but after you make the transaction on chain with that huge estimated gas fee, what happens?

Hello, sorry I was unable to answer last week.

Sorry I have to correct myself. When using testnet, on this case goerli, the gas fee is low (0.0000875GoerliETH) but when using Ethereum mainnet, for the same contract the gas is 1.2Eth. In BNB chain the same problem happens (gas fees around 0.66BNB, around 192$). On the other hand, on Polygon, gas fees stay acceptable, being only 2$.

Taking into account that on the test chains gas fees are reasonable and that on Polygon they stay low too, could this be related to the RPC used on the js to connect to this chains? Or is it a js problem (see code above) where I am incorrectly introducing the value. Maybe the problem is in solidity?

Another thing that may help you detect the problem is that, when the Metamask window appears to sign the token deployment I get the following error: “We could not estimate the gas. There could be an error in the contract and transaction may fail”. But when I deploy the contract on the testnet and check its supply and transaction fees it works perfectly.

Answering your question, on the testnet I do not have that huge transaction fee and when I deploy the contract it works perfectly. On the mainnets I have not payed the transaction fee, as it is around 600$ in real money :rofl:

Any help would be much appreciated,
Thank you and best regards

Usually this error shows when there will be a deploy issue, like the contract will generate an error on execution or it can also happen when you don’t have enough funds in the wallet and it is not able to estimate the gas fees because of that, did you try on multiple testnet networks?

Yes, on testnetworks I do not have that message. It only appears in BNB chain and Ethereum mainnets.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.