4

How to know the cryptocurrency used in a transaction through the transaction hash?

I'm using the following code:

<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>

...

if (typeof web3 !== 'undefined') {
      web3 = new Web3(web3.currentProvider);
    } else {
     web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }

    var transaction = web3.eth.getTransaction('0x42ca92e05d21592e92e36c93ae6e31d0583c4c95cadd42901e297b55c6b465af');
    console.log(transaction);

And I'm getting the object below:

Promise
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object
blockHash: "0x91a5799cac3de01498a4988d4e55bb29f6b56617490bf854ce5e1f21821db2e2"
blockNumber: 14832362
from: "0xdE4429D4cD2afa9C4314254F1cb074181f0e184e"
gas: 200000
gasPrice: "10000000000"
hash: "0x42ca92e05d21592e92e36c93ae6e31d0583c4c95cadd42901e297b55c6b465af"
input: "0x"
nonce: 12
r: "0xec1cb9f6b134c375542c4aaff07aa6ae8bd831918e52a609e77f227683524f67"
s: "0x798123f2eb75584430c2016cf91eeb384306291dcbc50eae64fc73c140cc972d"
to: "0x69AF47261C4585C365e4E1D93b635974a30fb117"
transactionIndex: 7
type: 0
v: "0x94"
value: "10000000000000000"
[[Prototype]]: Object

I find the value, the recipient, and the origin but I can't figure out where is any information about the uses token. I would be glad if someone helps me.

Yilmaz
  • 35,338
  • 10
  • 157
  • 202

1 Answers1

2

I do not think that you can get it from transaction hash: This is the break down of transaction hash:

0x
//  https://eth.wiki/fundamentals/rlp for more on f8
// 0xf8-0xf7=1byte=2 chars which tells you next 2 chars is the length of the paylaod
f8
// length of payload. 0x69=105bytes=210 chars. 
69
// Nonce. 1byte
12 
//0x85-0x80=133-128= 5bytes=10chars= GAS PRICE
85 012a05f200
// 0x83-0x80=131-128=3bytes=6chars= GAS LIMIT
83 07a120
// 0x94 - 0x80=148-128=20bytes=40chars= TO
94 b75fe87f44cb2003f3472424261f021d2100ce5a
// this should be value. empty valu, string is represended as 80
80 
// 0x84-0x80=132-128=4bytes=8 chars= DATA
84 3ccfd60b
// "v" value. 1byte
2a
// a0-0x80=160-128=32 bytes=64 chars= "r" VALUE
a0 fce2a70cde55dc86a203d2387469c36da00e9a9f3536b867f6761c314b1f1423
// a0-0x80=160-128=32 bytes=64 chars= "s" VALUE
a0 7b85742fd48a687b8daa097d1fb9d4b5135de6deb5b6fd16dd0f28d6c28727b6

To get an ERC20 transfer's information, you need the transaction receipt, since transfer information is recorded in a transfer event log. You should be using eth_getTransactionReceipt.

This post explains how to get it from transaction_receipt:

ERC20 Tokens Transferred Information from Transaction Hash

Yilmaz
  • 35,338
  • 10
  • 157
  • 202