[英]how can i identify type of transferd toke in my website
I want to create a dex website with solidity, web3, tronweb, and nodejs.我想用solidity、web3、tronweb和nodejs创建一个dex网站。
now I have a question about the transfer token in TRC-20 and ERC-20 network.现在我有一个关于 TRC-20 和 ERC-20 网络中的转移令牌的问题。
On my website use can deposit wallets from another site like bianance, coinbase, . . .
在我的网站上,使用可以从其他网站(如
bianance, coinbase, . . .
bianance, coinbase, . . .
and I create a TRC-20 or ERC-20 wallet address for he/she.我为他/她创建了一个 TRC-20 或 ERC-20 钱包地址。
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.也许用户想从我网站上的币
binance
等其他网站发送ADA
令牌。
i create a ERC-20 wallet address for user like this 0x5226a51522C23CcBEFd04a2d4C6c8e281eD1d680
,我为这样的用户创建了一个 ERC-20 钱包地址
0x5226a51522C23CcBEFd04a2d4C6c8e281eD1d680
,
user enter this address in the binance and send some ADA
token to his wallet in my website.用户在币安中输入此地址,然后将一些
ADA
代币发送到他在我网站上的钱包中。
now how can I know this token is ADA
, USDT
, or something else?现在我怎么知道这个代币是
ADA
、 USDT
还是别的什么?
For each EVM-compatible network (Etheruem, Tron, BSC, ...), you'll need to create a listener of the Transfer()
events of the ERC-20 tokens.对于每个与 EVM 兼容的网络(Etheruem、Tron、BSC,...),您需要创建 ERC-20 代币的
Transfer()
事件的侦听器。
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).您可以在 web3 文档中找到有关
subscribe()
function 的更多信息 - 例如如何仅过滤到您的地址的传输(此片段侦听您可能不需要的所有传输)。
For tokens on their own blockchain (such as ADA), you'll need to implement a custom listener for transfers.对于他们自己的区块链上的代币(例如 ADA),您需要为传输实现自定义侦听器。 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").
例如 USDT 在Ethereum 、 Tron 、 BSC等上有自己的代币(来源:USDT 的 CMC详细页面,选择框“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.因此,如果您允许用户在任何网络上向您转账
USDT
,您将需要监听所有这些网络上的传入转账。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.