通过RPC API(metAmask)发送令牌

发布于 2025-02-11 11:47:25 字数 706 浏览 2 评论 0原文

我在Ropsten网络上进行了USDC交易与代币的交易是直接触及的,我正在尝试一些我发现的事情而没有成功。我发现我从如何发送一些自定义的一个例子具有metamask api的令牌?

ethereum.request({
  method: "eth_sendTransaction",
  params: [
    {
      from: ethereum.selectedAddress,
      to: "0x07865c6E87B9F70255377e024ace6630C1Eaa37F",
      data: tokenContract.methods
        .transfer("My Wallet", "0.0001")
        .encodeABI(),
    }
  ]
});

这里的问题是未定义tokencontract,我不知道如何定义它,

我也发现了非常旧且真正过时的答案,其中大部分是使用Web3JS(并且MetAmask不允许使用MetAmask据我所知,与Web3J一起工作,我已经尝试过)。

I was doing a USDC transaction on the Ropsten network but in the Metamask documentation I didn't see any place where transactions with tokens were directly touched, I was trying some things I found without success. An example of what I found I took from How to send some custom tokens with MetaMask API?

ethereum.request({
  method: "eth_sendTransaction",
  params: [
    {
      from: ethereum.selectedAddress,
      to: "0x07865c6E87B9F70255377e024ace6630C1Eaa37F",
      data: tokenContract.methods
        .transfer("My Wallet", "0.0001")
        .encodeABI(),
    }
  ]
});

The problem here is that tokenContract is not defined and I have no idea how to define it

I also found VERY old and really obsolete answers, where mostly web3js is used (And MetaMask doesn't allow to work with web3js anymore as far as I understand, I've already tried it).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅黛梨妆こ 2025-02-18 11:47:25

在上面的示例中,tokencontract是要转移的令牌的地址。每个令牌合同都在某些地址上部署,例如 dai

另外,Web3JS确实支持MetAmask,请参阅此答案以进行示例实现。但是“ nofollow noreferrer”> metAmask不再注入web3js ,因此您需要需要将Web3J分别导入到Web应用程序中(以前可以使用MM注入的Web3)。

In the example above, tokenContract is address of the token that you want to transfer. Each token contract is deployed on some address, see for example USDT or DAI.

Also, web3js does support MetaMask, see this answer for an example implementation. But MetaMask no longer injects web3js, so that you need to import web3js into the web app separately (previously it was possible to use web3 injected by MM).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文