[英]How to transfer an ERC20 token between wallets with web3.py
我想知道,使用 web3.py 在两个钱包之间转移 ERC20 代币的正确方法是什么? 我正在测试 Rinkeby 测试网络上的所有内容。
这是我尝试过的...
from ethtoken.abi import EIP20_ABI
from web3 import Web3
token_from = "from_address"
token_to = "to_address"
token_to_private_key = "your_private_key"
#w3 = Web3(Web3.HTTPProvider(infura_url))
contractAddress = "contract_address"
infura_url = "https://rinkeby.infura.io/v3/your_infura_key"
# Fill in your infura API key here
w3 = Web3(Web3.HTTPProvider(infura_url))
contract = w3.eth.contract(address=contractAddress, abi=EIP20_ABI)
nonce = w3.eth.getTransactionCount(token_from)
# Build a transaction that invokes this contract's function, called transfer
token_txn = contract.functions.transfer(
token_to,
1,
).buildTransaction({
'chainId': 1,
'gas': 70000,
'gasPrice': w3.toWei('1', 'gwei'),
'nonce': nonce,
})
signed_txn = w3.eth.account.signTransaction(token_txn, private_key=token_to_private_key)
w3.eth.sendRawTransaction(signed_txn.rawTransaction)
当我尝试使用我的地址和私钥运行它时,我收到错误:ValueError: {'code': -32000, 'message': 'invalid sender'}
我怎样才能解决这个问题? 或者......有没有更好的方法来使用 web3.py 传输 erc20 令牌?
任何帮助表示赞赏。
谢谢
你好! 你应该使用'chainId': 4
用于 Rinkeby 测试网
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.