ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.97k stars 1.69k forks source link

[Help] send token BTC, eth, LTC, DASH, ... #1169

Closed henrytom1703 closed 5 years ago

henrytom1703 commented 5 years ago
from web3 import Web3
import web3
import json
from ethtoken.abi import EIP20_ABI
from eth_account import Account
etherscan_provider = Web3.HTTPProvider('https://ropsten.infura.io/v3/xxxxxxxxxxxx')
w3 = Web3(etherscan_provider)
print(w3.eth.getBalance(w3.toChecksumAddress('0x0AAeEFf32409E527e6A7A99e20c19559e35b3571')))
unicorns = w3.eth.contract('0x583cbBb8a8443B38aBcC0c956beCe47340ea1367', abi=EIP20_ABI)
print(unicorns)

nonce = w3.eth.getTransactionCount(w3.toChecksumAddress('0x7e0ad0312fbe8265c5286c97dd9a26940529118e'))

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

I want transfer a token from the address '0x0AAeEFf32409E527e6A7A99e20c19559e35b3571' to address '0x7e0ad0312fbe8265c5286c97dd9a26940529118e'? how to transfer a token?

What was wrong?

Error

5799816680000000000
<web3.utils.datatypes.Contract object at 0x7fbf0a15f668>
0
BokkyPooBah Test Token
Traceback (most recent call last):
  File "/home/tomtony/sourcecode/fx001/backend/TestH3.py", line 32, in <module>
    'nonce': nonce
  File "/home/tomtony/python_env/test-env/lib/python3.6/site-packages/web3/contract.py", line 1228, in buildTransaction
    **self.kwargs
  File "/home/tomtony/python_env/test-env/lib/python3.6/site-packages/web3/contract.py", line 1509, in build_transaction_for_function
    fn_kwargs=kwargs,
  File "/home/tomtony/python_env/test-env/lib/python3.6/site-packages/web3/utils/contracts.py", line 188, in prepare_transaction
    validate_payable(transaction, fn_abi)
  File "/home/tomtony/python_env/test-env/lib/python3.6/site-packages/web3/utils/contracts.py", line 263, in validate_payable
    "Sending non-zero ether to a contract function "
web3.exceptions.ValidationError: Sending non-zero ether to a contract function with payable=False. Please ensure that transaction's value is 0.

Process finished with exit code 1
pipermerriam commented 5 years ago

I'm closing only because this isn't a bug. You may get a quicker response asking your question on the ethereum stackexchange site: https://ethereum.stackexchange.com/

pipermerriam commented 5 years ago

Also, this may get you started: https://web3py.readthedocs.io/en/stable/examples.html#interacting-with-an-erc20-contract