我正在尝试使用本地私钥在带有 web3.py 的 python 中发送 ERC20 令牌。
使用此代码,我可以发送以太:
w3 = Web3(HTTPProvider('https://api.myetherapi.com/eth'))
signed_txn = w3.eth.account.signTransaction(dict(
nonce=w3.eth.getTransactionCount(from_address),
gasPrice=w3.eth.gasPrice,
gas=100000,
to=to_address,
value=12345,
data=b'',
),
private_key,
)
w3.eth.sendRawTransaction(signed_txn.rawTransaction)
Run Code Online (Sandbox Code Playgroud)
然后我也发现了这个,但是估计Gas总是出错,在我看来,我无法像这样指定我发送的地址或通过某种签名证明它是我的地址?
contract = w3.eth.contract(address=address, abi=EIP20_ABI, bytecode=bytecode)
contract.functions.transfer(to_address, 121212).transact()
Run Code Online (Sandbox Code Playgroud)
所以我有 JSON abi、字节码、地址和我的私钥,我可以用我找到的代码以某种方式构建一个工作脚本吗?
提前致谢!