web3.py开发之坑

  • Could not transact with/call contract function, is contract deployed correctly and chain synced
    智能合约的函数调用有如下两种方式:
# Execute smart contract function in the EVM without sending any transaction
myContract.functions.myFunction([param1]).call(options[])

# Will send a transaction to the smart contract and execute its function
myContract.functions.myFunction([param1]).transact(options[])

call不改变合约状态,read only;transact可能会改变合约状态,R&W

  • gas required exceeds allowance or always failing transaction
    没有设定transaction的gasLimit,如下设定
myContract.functions.name().call({"gasLimit":100000})
  • gas required exceeds block gasLimit
    这个问题就很诡异,因为节点的blockNumber始终为0,导致block的gasLimit一直为创世节点的5000。
    最终通过修改指令,加上 --syncmode light 让节点可以接受、广播transaction,最终解决问题
geth --datadir data --syncmode fast --rpcapi eth,web3,personal --rpc --cache=2048  console 2>>test.log
> eth.blockNumber
> 0
> eth.getBlock("latest")
> ...
  • 其它问题
    • transfer之前需要unlock account
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容