ethereum ganache 失败并显示 "Exceeds block gas limit" 即使我有足够的余额

ethereum ganache is failing with "Exceeds block gas limit" even though I have enough balance

我正在使用 ganache 和 web3 测试以太坊智能合约。

const Web3 = require('web3');
const web3 = new Web3(provider);
const contract = new web3.eth.Contract(abi, contractAddress);

web3.eth.getBalance(contractOwner).then(console.log); // this returns 99953972490000000000

const sendTxOptions = {from: contractOwner, gas: 1000*1000*10}
contract.methods.my_method().send(sendTxOptions).then(console.log);

(node:80755) UnhandledPromiseRejectionWarning: Error: Returned error: Exceeds block gas limit

1000*1000*10 小于 99953972490000000000。为什么会失败?

注意:我已经搜索过其他类似的问题,例如这个,但他们没有回答我的问题。 https://ethereum.stackexchange.com/questions/26577/error-vm-exception-while-processing-transaction-out-of-gas

它是 ETH 余额(不是 gas):

web3.eth.getBalance(contractOwner).then(console.log); // this returns 99953972490000000000

改用estimateGashttps://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#methods-mymethod-estimategas

my_method()block gas limit 消耗更多 gas。可以为Ganache提高区块的gas limit,但最好优化一下功能,否则在真实网络中可能还是会出问题。