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
  • 备注
    • web3py地址: https://web3py.readthedocs.io/en/stable/quickstart.html
    • blockNumber始终为0的讨论:https://github.com/ethereum/go-ethereum/issues/16147

你可能感兴趣的:(web3.py开发之坑)