Python 如何使用web3.py在钱包之间传输ERC20代币

Python 如何使用web3.py在钱包之间传输ERC20代币,python,web3,erc20,Python,Web3,Erc20,我想知道,使用web3.py在两个钱包之间传输ERC20代币的正确方式是什么?我正在林克比测试网络上测试一切 这是我试过的 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.py在两个钱包之间传输ERC20代币的正确方式是什么?我正在林克比测试网络上测试一切

这是我试过的

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令牌

感谢您的帮助

谢谢

嗨!您应该为Rinkeby testnet使用
'chainId':4