I am using web3.eth.Contract
to deploy a smart contract to the ropsten testnet. To interact with metamask I am using window.ethereum
. I deploy the contract via the code below that I found on https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#id25:
myContract.deploy({
data: '0x12345...',
arguments: [123, 'My String']
})
.send({
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
}, function(error, transactionHash){ ... })
.on('error', function(error){ ... })
.on('transactionHash', function(transactionHash){ ... })
.on('receipt', function(receipt){
console.log(receipt.contractAddress) // contains the new contract address
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // instance with the new contract address
});
Regarding the changes in gas that came wit EIP-1559 according to the top answer on this question: Sending transactions after London Fork considering EIP 1559 it's required to set "maxFeePerGas"
and "maxPriorityFeePerGas"
like in the example below:
{
"gas": "0x5208", // = gasLimit
"maxFeePerGas": "0xb2d05e00",
"maxPriorityFeePerGas": "0xb2d05e00",
"input": "0x", // = data
"nonce": "0xa",
"to": "0xc6d5a3c98ec9073b54fa0969957bd582e8d874bf",
"value": "0x0",
"accessList": [],
"chainId": "0x5"
}
In the example above the values for maxPriorityFeePerGas, maxFeePerGas
are hard coded, but it would be better if metamask could suggest values on contract deployment.
Can gas price ("maxFeePerGas" and "maxPriorityFeePerGas"
) and amount of gas be automatically set by metamask according to the ethereum network congestion at time of deploying the contract, or is it required to be set via code in web3.js?
If gas price can't be set automatically by metamask, what are the new web3.js functions to estimate baseFeePerGas, maxPriorityFeePerGas, maxFeePerGas
.
Prior to EIP-1559 I used web3.eth.getGasPrice()
to estimate gas.