zksync-web-era-docs
zksync-web-era-docs copied to clipboard
python SDK eth_estimate_gas too little gas can cause transactions to fail
How to reproduce
use zkSync_web3.zksync.eth_estimate_gas(tx)
to estimate gas.
result: transactions will fail.
log
tx status: AttributeDict({'blockHash': HexBytes('0x47c258f4d17c096efd397fde3bbd49121765a00f548e0f1f273bb6eee086a1e1'), 'blockNumber': 3884831, 'contractAddress': None, 'cumulativeGasUsed': 0, 'effectiveGasPrice': 100000000, 'from': '0x2C315eDC63CeB0CE6CB53FBc398EEab5fa4B57B0', 'gasUsed': 2577645, 'l1BatchNumber': None, 'l1BatchTxIndex': None, 'l2ToL1Logs': [], 'logs': [AttributeDict({'address': '0x000000000000000000000000000000000000800A', 'blockHash': HexBytes('0x47c258f4d17c096efd397fde3bbd49121765a00f548e0f1f273bb6eee086a1e1'), 'blockNumber': 3884831, 'data': '0x0000000000000000000000000000000000000000000000000000ea54e8917800', 'l1BatchNumber': None, 'logIndex': 0, 'logType': None, 'removed': False, 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), HexBytes('0x0000000000000000000000002c315edc63ceb0ce6cb53fbc398eeab5fa4b57b0'), HexBytes('0x0000000000000000000000000000000000000000000000000000000000008001')], 'transactionHash': HexBytes('0xe59614b25547b2ec1d98815489397a7bf30d3ef0708bb6d38419af253eee68cb'), 'transactionIndex': 0, 'transactionLogIndex': '0x0'})], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'root': '0x47c258f4d17c096efd397fde3bbd49121765a00f548e0f1f273bb6eee086a1e1', 'status': 0, 'to': '0x2C315eDC63CeB0CE6CB53FBc398EEab5fa4B57B0', 'transactionHash': HexBytes('0xe59614b25547b2ec1d98815489397a7bf30d3ef0708bb6d38419af253eee68cb'), 'transactionIndex': 0, 'type': '0x71'})
solution
use estimate_gas = int(zkSync_web3.zksync.eth_estimate_gas(tx) * 1.3)
the transfer is OK
tx status: AttributeDict({'blockHash': HexBytes('0x3dde9233f931390896fa6a34d322dfd9c1f1fb5bb1c3390d291cf41560eece7c'), 'blockNumber': 3884126, 'contractAddress': None, 'cumulativeGasUsed': 0, 'effectiveGasPrice': 100000000, 'from': '0x2C315eDC63CeB0CE6CB53FBc398EEab5fa4B57B0', 'gasUsed': 3116635, 'l1BatchNumber': None, 'l1BatchTxIndex': None, 'l2ToL1Logs': [], 'logs': [AttributeDict({'address': '0x000000000000000000000000000000000000800A', 'blockHash': HexBytes('0x3dde9233f931390896fa6a34d322dfd9c1f1fb5bb1c3390d291cf41560eece7c'), 'blockNumber': 3884126, 'data': '0x000000000000000000000000000000000000000000000000000130a1938bef00', 'l1BatchNumber': None, 'logIndex': 0, 'logType': None, 'removed': False, 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), HexBytes('0x0000000000000000000000002c315edc63ceb0ce6cb53fbc398eeab5fa4b57b0'), HexBytes('0x0000000000000000000000000000000000000000000000000000000000008001')], 'transactionHash': HexBytes('0xb82c1a6a5960ed0f8232a89e5b61238bdda7a3fcb5f4d7f82434326817441281'), 'transactionIndex': 0, 'transactionLogIndex': '0x0'}), AttributeDict({'address': '0x000000000000000000000000000000000000800A', 'blockHash': HexBytes('0x3dde9233f931390896fa6a34d322dfd9c1f1fb5bb1c3390d291cf41560eece7c'), 'blockNumber': 3884126, 'data': '0x00000000000000000000000000000000000000000000000000038d7ea4c68000', 'l1BatchNumber': None, 'logIndex': 1, 'logType': None, 'removed': False, 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), HexBytes('0x0000000000000000000000002c315edc63ceb0ce6cb53fbc398eeab5fa4b57b0'), HexBytes('0x0000000000000000000000002c315edc63ceb0ce6cb53fbc398eeab5fa4b57b0')], 'transactionHash': HexBytes('0xb82c1a6a5960ed0f8232a89e5b61238bdda7a3fcb5f4d7f82434326817441281'), 'transactionIndex': 0, 'transactionLogIndex': '0x1'})], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'root': '0x3dde9233f931390896fa6a34d322dfd9c1f1fb5bb1c3390d291cf41560eece7c', 'status': 1, 'to': '0x2C315eDC63CeB0CE6CB53FBc398EEab5fa4B57B0', 'transactionHash': HexBytes('0xb82c1a6a5960ed0f8232a89e5b61238bdda7a3fcb5f4d7f82434326817441281'), 'transactionIndex': 0, 'type': '0x71'})
conclusion
python SDK eth_estimate_gas is not correct.
@fabius8 any reason why the estimated gas was multiplied by 1.3 from your proposed solution?
Hi there, sorry for delay in getting back to you, we are currently in the process of updating the Python SDK since the recent release. We're making a note on the docs about this so please check back at that time and let us know if the issue is still happening. For now, I'm going to close this one.