[Ethereum] Ethers js estimate gas offline

ethers.jsgas-pricejavascript

Looking here in the docs it mentions I need to have the provider attached to estimate gas. But for formatting a transaction offline, I dont have access to the provider. Is there a way to estimate the gas when you dont have access to the provider? I tried sending the transaction without gasPrice and it worked… however, should I provide this price in my formatted offline transaction? Here is how I am formatting my transaction without provider:

const iface = new ethers.utils.Interface(abi);
const func = iface.functions.setValues.encode([name, value]);
const nonce = await NonceManager.requestNonce(wallet);
const txs = {
  gasLimit: 1000001,
  data: func,
  to: address,
  nonce: nonce,
}
const iSign = await wallet.sign(txs);

The iSign is my transaction to send when needed. But is there a way to estimate gase without provider?

Best Answer

https://docs.ethers.io/ethers.js/html/api-contract.html

see details from the documentations of etherjs v4 https://docs.ethers.io/ethers.js/html/api-contract.html

Related Topic