I am using below code to call a smart contract method on Ethereum network.
const w = new Web3(url);
await w.eth.accounts.signTransaction(
{
from: account.address,
to: contractAddress,
gas: 1000000,
gasPrice: 1000000000,
nonce: await w.eth.getTransactionCount(account.address),
data: await contract.methods
.createSector(
{ value: web3.utils.fromWei(price, 'ether') }
)
.encodeABI(),
},
privateKey
);
In above code, it requires gas
and gasPrice
parameters. I need to set the value when calling the contract method. My question is how I know what the right value to set? I thought those values are not static which can be set during runtime when Metamask is open. Do I misunderstand anything on gas?