1
  1. How can i read symbol and name of the token in transaction? I tried to decode input data from transaction, but it wasn't success. the latest Web3j does not have toAscii method in java.

  2. Should i use parity tracer for this? What advantages of tracing? Internal transactions?

Thanks

2

Based on answer of Mikko Ohtamaa, i propose the following python code:

if __name__ == "__main__":

    EIP20_ABI = json.loads(
        '[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}]')  # noqa: 501

    address = w3.toChecksumAddress("0x384776cb3E453402eCF070B48D79e9874763CB50")

    token_contract = contract = w3.eth.contract(address, abi=EIP20_ABI, ContractFactoryClass=ConciseContract)

    print(token_contract.symbol())
    print(token_contract.name())

The main differences are:

  1. use Factory (no needs to invoke functions method)

  2. transform hash contract address to checksum.

  3. define json schema for the data decoding in python code.

In Java you should do the same.

| improve this answer | |
1

In the Transaction Input there is usally(ERC20) nothing about the name or symbol of the Token, however you can get the address of smartcontract from the Transaction (not Input), and then you can get the name and symbol with a callable getter function to that smart contract.

see in documentation :

https://docs.web3j.io/transactions.html

down at: "Querying the state of a smart contract"

| improve this answer | |
  • @YakovenkoAlexey if you still have the problem, i can help you at the weekend – Majd TL Nov 30 '18 at 8:55
0

The symbol and name are found in the token contract as publicly callable getter functions. You can find them out by issuing a proper call() against the token smart contract and call symbol() and name() functions.

Here is an example for Web3 Python (should be similar for Java):

 # ABI is ERC-20 API as a JSON
 token_contract = web3.eth.contract(abi=token_abi, address=token_address) 
 print(token_contract.functions.symbol().call())
 print(token_contract.functions.name().call())
| improve this answer | |

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.