0

I want to use web3.py to send some EOS. Here is my code:

from ethtoken.abi import EIP20_ABI
from web3 import Web3, HTTPProvider

infura_provider = HTTPProvider('https://mainnet.infura.io/CMI5Z7n7hAy8CP7nx95s')
w3 = Web3(infura_provider)
w3.eth.enable_unaudited_features()

contract_Address = w3.toChecksumAddress("0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0")
unicorns = w3.eth.contract(contract_Address, abi=EIP20_ABI)

nonce = w3.eth.getTransactionCount('0x030eC1E9E2AfA4A59a7C56F2B761505E1a414b45')

unicorn_txn = unicorns.functions.transfer(
    '0xFe0196504dF34c4Bf30D3089EfFf86cFe3B34617',
    1,
).buildTransaction({
    'chainId': 1,
    'gas': 200000,
    'value': int(0.1 * (10 ** 18)),  # EOS:18 decimals
    'gasPrice': w3.toWei('4', 'gwei'),
    'nonce': nonce,
})

private_key = 'my private key'
signed_txn = w3.eth.account.signTransaction(unicorn_txn, private_key=private_key)

TxHash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
print(TxHash.hex())

The code runs without error and print out the TxHash,but the transaction failed,the specific reason can be found here:transaction information

I don't know how to fix this,can anyone help me?Thanks!

0

I found the solution: the value should be 0,since I want to transfer token,not eth.

unicorn_txn = unicorns.functions.transfer(
'0xFe0196504dF34c4Bf30D3089EfFf86cFe3B34617',
1,
).buildTransaction({
    'chainId': 1,
    'gas': 200000,
    'value': 0
    'gasPrice': w3.toWei('4', 'gwei'),
    'nonce': nonce,
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.