0

I want to create a dex website with solidity, web3, tronweb, and nodejs .

now I have a question about the transfer token in TRC-20 and ERC-20 network.

On my website use can deposit wallets from another site like bianance , coinbase , . . . and I create a TRC-20 or ERC-20 wallet address for he/she.

in both networks exists many tokens now my question is this, how can I know the user sent or receive which token?

maybe users wants to send ADA token from another websites like binance on my website.

i create a ERC-20 wallet address for user like this 0x5226a51522C23CcBEFd04a2d4C6c8e281eD1d680 ,

user enter this address in the binance and send some ADA token to his wallet in my website .

now how can I know this token is ADA, USDT, or something else?

Mr Coder
  • 761
  • 2
  • 13
  • 34

1 Answers1

1

For each EVM-compatible network (Etheruem, Tron, BSC, ...), you'll need to create a listener of the Transfer() events of the ERC-20 tokens.

web3.eth.subscribe("logs", {
    address: [
        "0xdac17f958d2ee523a2206206994597c13d831ec7", // Ethereum USDT address
        // can add other tokens
    ],
    topics: [
        // keccak256 hash of the "Transfer(address,address,uint256)" event signature
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
    ]
}, (err, event) => {
    console.log(event);
});

You can find more info about the subscribe() function in the web3 docs - for example how to only filter transfers to your addresses (this snippet listens to all transfers, that you might not need).


For tokens on their own blockchain (such as ADA), you'll need to implement a custom listener for transfers. The architecture of the listener might need to be different on each network - possibly some have a way to emit events on a transfer, and with some you'll need to scan each block to get the transactions to your address.

Mind that some cryptocurrencies are based on multiple networks. For example USDT has their own token on Ethereum, Tron, BSC and others (source: CMC detail page of USDT, selectbox "Explorers"). So if you allow users to transfer you USDT on any network, you'll need to listen to incoming transfers on all these networks.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • hi , thanks for answer my question , but I can't understand . i think better I explain my problem again . i using the `TRC-20` with tronweb , using `ERC-20` with web3 . in web3 I create a wallet for user . user need transfer `SHIB` from finance to my website . now how can I identify with coin was transfer from finance to my website . for all token i use this code for create wallet : `web3.eth.accounts.create();` – Mr Coder Dec 14 '21 at 12:58
  • @Kianoush Since `SHIB` runs on the Ethereum network, you can use the `subscribe()` function from the first part of the question. This will invoke the callback when a `SHIB` transfer occurs. You can extend the filter using examples from the documentation to invoke the callback only when a transfer to your address occurs. – Petr Hejda Dec 14 '21 at 13:43
  • should i add contract address of `SHIB` or `USDT` token in subscribe ? – Mr Coder Dec 14 '21 at 14:18
  • @Kianoush If you want to subscribe to events of SHIB - pass the SHIB address. If you want to subscribe to events of USDT - pass the USDT address. If you want to subscribe to events of both - pass both in an array (instead of the string). – Petr Hejda Dec 14 '21 at 14:21
  • thnak you . . .. – Mr Coder Dec 14 '21 at 18:57