bsc-php icon indicating copy to clipboard operation
bsc-php copied to clipboard

How to get transaction detail when transfer is token?

Open aliqasemzadeh opened this issue 2 years ago • 21 comments

How to get transaction detail when the transfer is a token?

aliqasemzadeh avatar May 19 '23 14:05 aliqasemzadeh

https://github.com/Fenguoz/bsc-php/blob/916a96185790d50dc0e838ae19543f4e0fce1cd4/README.md?plain=1#L35

Fenguoz avatar May 31 '23 01:05 Fenguoz

@Fenguoz Hi It didn't get transaction detail when it is token transfer.

my code is:

        $uri = 'https://bsc-dataseed1.defibit.io/';// Mainnet
        $api = new \Binance\NodeApi($uri);

        $config = [
            'contract_address' => '0x55d398326f99059ff775485246999027b3197955',// USDT BEP20
            'decimals' => 18,
        ];
        $bep20 = new \Binance\BEP20($api, $config);
        $txHash = '0x60c6ff9b16ddf2372cb7f8a1c02c990ae5c93162cf0bc8a866000a122dfba401';
        var_dump($bep20->getTransactionReceipt($txHash));

output :

array(14) {
  ["blockHash"]=>
  string(66) "0xfaa6ab98a791e6ef6cb70ebc9d611f074325b5550e0fae4972c2a8c1262c8ba7"
  ["blockNumber"]=>
  string(9) "0x1b694c6"
  ["contractAddress"]=>
  NULL
  ["cumulativeGasUsed"]=>
  string(8) "0xb67fb6"
  ["effectiveGasPrice"]=>
  string(10) "0xb2d05e00"
  ["from"]=>
  string(42) "0x392760369e0d81a156d7231a3fe177dba97dd22b"
  ["gasUsed"]=>
  string(6) "0x527b"
  ["logs"]=>
  array(1) {
    [0]=>
    array(9) {
      ["address"]=>
      string(42) "0x55d398326f99059ff775485246999027b3197955"
      ["topics"]=>
      array(3) {
        [0]=>
        string(66) "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
        [1]=>
        string(66) "0x000000000000000000000000392760369e0d81a156d7231a3fe177dba97dd22b"
        [2]=>
        string(66) "0x00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a6"
      }
      ["data"]=>
      string(66) "0x0000000000000000000000000000000000000000000000056bc75e2d63100000"
      ["blockNumber"]=>
      string(9) "0x1b694c6"
      ["transactionHash"]=>
      string(66) "0x60c6ff9b16ddf2372cb7f8a1c02c990ae5c93162cf0bc8a866000a122dfba401"
      ["transactionIndex"]=>
      string(4) "0x6f"
      ["blockHash"]=>
      string(66) "0xfaa6ab98a791e6ef6cb70ebc9d611f074325b5550e0fae4972c2a8c1262c8ba7"
      ["logIndex"]=>
      string(4) "0xcd"
      ["removed"]=>
      bool(false)
    }
  }
  ["logsBloom"]=>
  string(514) "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010080000000000000001000008000000000000000
000000000000200000000000000400000000000000000000000000000000000000000000000000010000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000020000000000000000000200000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000"
  ["status"]=>
  string(3) "0x1"
  ["to"]=>
  string(42) "0x55d398326f99059ff775485246999027b3197955"
  ["transactionHash"]=>
  string(66) "0x60c6ff9b16ddf2372cb7f8a1c02c990ae5c93162cf0bc8a866000a122dfba401"
  ["transactionIndex"]=>
  string(4) "0x6f"
  ["type"]=>
  string(3) "0x0"
}

There is no detail about the amount and which address get tokens.

aliqasemzadeh avatar Jun 02 '23 07:06 aliqasemzadeh

Added getTransactionByHash interface to update the latest package can be used https://github.com/Fenguoz/bsc-php/blob/b6d72bb6ddd2e178f9e8811b6697cac85ac90a0a/README.md?plain=1#L36

Fenguoz avatar Jun 02 '23 08:06 Fenguoz

array(15) {
  ["blockHash"]=>
  string(66) "0xfaa6ab98a791e6ef6cb70ebc9d611f074325b5550e0fae4972c2a8c1262c8ba7"
  ["blockNumber"]=>
  string(9) "0x1b694c6"
  ["from"]=>
  string(42) "0x392760369e0d81a156d7231a3fe177dba97dd22b"
  ["gas"]=>
  string(7) "0x30d40"
  ["gasPrice"]=>
  string(10) "0xb2d05e00"
  ["hash"]=>
  string(66) "0x60c6ff9b16ddf2372cb7f8a1c02c990ae5c93162cf0bc8a866000a122dfba401"
  ["input"]=>
  string(138) "0xa9059cbb00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a60000000000000000000000000000000000000000000000056bc75e2d63100000"
  ["nonce"]=>
  string(5) "0x3ee"
  ["to"]=>
  string(42) "0x55d398326f99059ff775485246999027b3197955"
  ["transactionIndex"]=>
  string(4) "0x6f"
  ["value"]=>
  string(3) "0x0"
  ["type"]=>
  string(3) "0x0"
  ["v"]=>
  string(4) "0x93"
  ["r"]=>
  string(66) "0x1c59dfc1ab96126010300040e451375aaa13b15f86930df72e3fe09b2928a951"
  ["s"]=>
  string(66) "0x44b25765a3268e457013ec144caa6532d476aae17f96a84449155527dfbdced1"
}

Yet no detail about token transaction.

aliqasemzadeh avatar Jun 02 '23 09:06 aliqasemzadeh

You must decode this, Here are the details of the token transaction.

["input"]=> string(138) "0xa9059cbb00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a60000000000000000000000000000000000000000000000056bc75e2d63100000"

This part refers to the token contract address: USDT

["to"]=> string(42) "0x55d398326f99059ff775485246999027b3197955"

You need to decode the 'input' using an 'ABI' decoder.

kendol07 avatar Jun 16 '23 11:06 kendol07

@kendol07 Can you give me ABI decoder?

aliqasemzadeh avatar Jun 17 '23 05:06 aliqasemzadeh

Use this repository that I have created for you: https://github.com/kendol07/eth_abi_decoder".

kendol07 avatar Jun 17 '23 13:06 kendol07

@Fenguoz @kendol07 I think we need to add a method that decodes.

aliqasemzadeh avatar Jun 26 '23 14:06 aliqasemzadeh

@Fenguoz if you want you can use my code to implement here.

kendol07 avatar Jun 26 '23 15:06 kendol07

I have created this latest version, which can decode input data from ERC20, BEP20, Polygon, and all Ethereum-based transfer transactions, without needing an ABI. It's easy to use, and it can be improved and adapted to this same project. It allows for the decoding of BEP20 transactions of USDT, USDC, and any other token.

https://github.com/kendol07/Ethereum.Input.Data.Decoder

kendol07 avatar Jan 18 '24 20:01 kendol07

@kendol07 Could please give us example to use it.

aliqasemzadeh avatar Jan 19 '24 01:01 aliqasemzadeh

You pass the parameter ["input"]=> string(138) "0xa9059cbb00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a60000000000000000000000000000000000000000000000056bc75e2d63100000" and decode it using the function available at https://github.com/kendol07/Ethereum.Input.Data.Decoder. Upon decoding, you will obtain the recipient and the amount of the USDT transaction and any other token.

Example:

require DIR."/vendor/autoload.php"; require 'decoder.php';

$inputData='0xa9059cbb00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a60000000000000000000000000000000000000000000000056bc75e2d63100000';

$result= DecodeDataInput($inputData); echo $result;

Example result: { "address": "0x123...", "value": "10000" //wei }

kendol07 avatar Jan 19 '24 02:01 kendol07

You pass the parameter ["input"]=> string(138) "0xa9059cbb00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a60000000000000000000000000000000000000000000000056bc75e2d63100000" and decode it using the function available at https://github.com/kendol07/Ethereum.Input.Data.Decoder. Upon decoding, you will obtain the recipient and the amount of the USDT transaction and any other token.

Example:

require DIR."/vendor/autoload.php"; require 'decoder.php';

$inputData='0xa9059cbb00000000000000000000000065624442e8916b8cd4bc7c57388461bdc1bbe1a60000000000000000000000000000000000000000000000056bc75e2d63100000';

$result= DecodeDataInput($inputData); echo $result;

Example result: { "address": "0x123...", "value": "10000" //wei }

its not work. Warning: Undefined array key "value" in decoder.php on line 34 i put input from getTransactionByHash

darknaut avatar Jan 19 '24 18:01 darknaut

I have created this latest version, which can decode input data from ERC20, BEP20, Polygon, and all Ethereum-based transfer transactions, without needing an ABI. It's easy to use, and it can be improved and adapted to this same project. It allows for the decoding of BEP20 transactions of USDT, USDC, and any other token.

https://github.com/kendol07/Ethereum.Input.Data.Decoder

even im testing using from your input data, its error too. are done testing in other platform?

darknaut avatar Jan 19 '24 18:01 darknaut

Test it now, the code has been modified. It had a small error because I translated it into English for you to understand.

kendol07 avatar Jan 19 '24 19:01 kendol07

Test it now, the code has been modified. It had a small error because I translated it into English for you to understand.

ok its work, are you know how to get transaction by address?

darknaut avatar Jan 19 '24 19:01 darknaut

I use the scanning of transactions by blocks and in each transaction of the block, I check if the recipient belongs to any of my wallets. But you can also use this API that allows you to obtain transactions by address.

https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-normal-transactions-by-address

kendol07 avatar Jan 19 '24 19:01 kendol07

i dont want via bsc api, i want from rpc so it free, can you help me?

I use the scanning of transactions by blocks and in each transaction of the block, I check if the recipient belongs to any of my wallets. But you can also use this API that allows you to obtain transactions by address.

https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-normal-transactions-by-address

darknaut avatar Jan 19 '24 19:01 darknaut

Register on BSC and you will get an API, it's free for some features including Transactions by Address.

kendol07 avatar Jan 19 '24 20:01 kendol07

free but limit, there are no features get tx by address? eth_getLogs i think its not work now

darknaut avatar Jan 19 '24 20:01 darknaut

I use block scanning. A script scans the new blocks, and when it finds a transaction that corresponds to your wallet, you store it for whatever use you want.Other than that, I couldn't help you; I don't use address scanning in any other way than what has already been explained.

kendol07 avatar Jan 19 '24 20:01 kendol07