小编use*_*065的帖子

使用本地私钥通过 web3.py 发送 ERC20 令牌

我正在尝试使用本地私钥在带有 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、字节码、地址和我的私钥,我可以用我找到的代码以某种方式构建一个工作脚本吗?

提前致谢!

python token ethereum web3-donotuse erc20

7
推荐指数
1
解决办法
4950
查看次数

标签 统计

erc20 ×1

ethereum ×1

python ×1

token ×1

web3-donotuse ×1