https://goerli.etherscan.io/tx/0x76e440006690c02f87d110c3389e8738e56fcbcd454a29cf24154bfee4d49576
为什么此交易失败?
编辑1:web3 py代码
contract_address = "0x07865c6E87B9F70255377e024ace6630C1Eaa37F"
contract = web3.eth.contract(contract_address, abi=token_abi)
print(f"My balance: {contract.functions.balanceOf(my_account.address).call()}")
print(f"Receiver balance: {contract.functions.balanceOf(receiver_address).call()}")
raw_txn = {
"from": my_account.address,
"gasPrice": web3.eth.gasPrice,
"gas": 200000,
"to": contract_address,
"value": 0,
"data": contract.encodeABI('transfer', args=(receiver_address, 1234567)),
"nonce": web3.eth.getTransactionCount(my_account.address)
}
signed_txn = web3.eth.account.signTransaction(raw_txn, PRIVATE_KEY)
web3.eth.sendRawTransaction(signed_txn.rawTransaction)enter code here
编辑2:我把它改为使用合同转移函数,现在它工作了。我不知道的原因
value = 100000
contract_call = contract.functions.transfer(receiver_address, value)
unsigned_txn = contract_call.buildTransaction({'chainId': web3.eth.chainId,
'from': my_account.address,
"nonce": web3.eth.getTransactionCount(my_account.address),
'gasPrice': web3.eth.gasPrice})
signed_txn = web3.eth.account.signTransaction(unsigned_txn, PRIVATE_KEY)
# signed_txn = web3.eth.account.signTransaction(raw_txn, PRIVATE_KEY)
web3.eth.sendRawTransaction(signed_txn.rawTransaction)
signed_txn.hash
web3.toHex(web3.keccak(signed_txn.rawTransaction))
#waits for transaction to complete
tx_receipt = web3.eth.wait_for_transaction_receipt(signed_txn.hash)
tx_receipt['status']
print(f"My balance: {contract.functions.balanceOf(my_account.address).call()}")
print(f"Receiver balance: {contract.functions.balanceOf(receiver_address).call()}")
交易具有非零ETHvalue
。
代理约定会将其正确重定向到实现约定。但是实现的transfer()
函数没有使用payable
修饰符,因此它不能接受ETH值。交易失败。