如何从JavaScript中找出IERC20令牌地址
我想将一些IERC20令牌从MetAmask发送到由我的网页控制的合同,
我将HTML按钮操作链接到以下JavaScript函数。 现在,当MetAmask接受MetAmask的确认/链接帐户使用网页上的网页中,现在为IERC20代币发送了Ether时
const placeFunds = async (side, e) => {
e.preventDefault();
await contract.getFunds(
side,
{value: e.target.elements[0].value}
);
,这效果很好,我想在传递合同功能之前弄清楚IERC20代币地址。 JavaScript中存储的令牌地址在哪里/我如何获得该信息,因为我希望合同仅接受特定的ERC20令牌?
const placeFunds = async (side, e) => {
e.preventDefault();
await contract.getFunds(
side, TOKENADDRESS,
{value: e.target.elements[0].value}
);
I would like to send some IERC20 tokens from metamask to a contract controlled by my webpage
I link an HTML button action to the following javascript function. This works well when ether is sent directly from metamask after accepting confirming/linking account from metamask with webpage
const placeFunds = async (side, e) => {
e.preventDefault();
await contract.getFunds(
side,
{value: e.target.elements[0].value}
);
Now for the IERC20 token, I would like to figure out the IERC20 token address before passing to the contract function. Where is the token address stored in javascript/how do I get that info, as I want the contract to accept only specific ERC20 tokens?
const placeFunds = async (side, e) => {
e.preventDefault();
await contract.getFunds(
side, TOKENADDRESS,
{value: e.target.elements[0].value}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令牌没有存储在JavaScript中。每当您希望在MetAmask中添加新的令牌时,您可能必须自己添加它,因为MetAmask也不知道。如果您不知道要转移的令牌,则可以使用一些工具,例如 Moralis 使用用户的所有ERC20令牌
Moralis.web3.getAllerc20
The tokens are not stored in javascript. Whenever you want a new token to be added in metamask, you might have to add it yourself because metamask also doesn't know about it. If you don't know the token you are going to transfer, you can use some tool like Moralis to get all erc20 tokens of the user with
Moralis.Web3.getAllERC20