Solana工资交易请求可以比扫描QR码的钱包的公众返回更多吗?

发布于 2025-02-07 16:10:06 字数 50 浏览 0 评论 0 原文

例如,我们如何从扫描Solana Pay QR码的钱包中获得特定SPL令牌的确切平衡?

For example, how can we get the exact balances of specific SPL tokens from a wallet that scans a Solana Pay QR code?

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

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

发布评论

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

评论(1

听风吹 2025-02-14 16:10:06

尝试使用“@solana/spl-token”的

导入{getorCreateAssociatedTokenAccount};

扫描QR代码扫描后,解析URL您将获得SPL-Toke

  const tokenAcc = await getOrCreateAssociatedTokenAccount(
    provider.connection,
    owner,
    new anchor.web3.PublicKey(
      parsed_spl_token_from_qr_code
    ),
    provider.wallet.publicKey
  );

  const accInfo = await provider.connection.getTokenAccountBalance(
    tokenAcc.address
  );
  console.log(
    "Balance ",
    Number(accInfo.value.amount) / anchor.web3.LAMPORTS_PER_SOL
  );

Try this

import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token";

https://github.com/solana-labs/solana-pay/blob/master/core/src/parseURL.ts#L78

After scanning QR code scan, parse the url you will get spl-token

  const tokenAcc = await getOrCreateAssociatedTokenAccount(
    provider.connection,
    owner,
    new anchor.web3.PublicKey(
      parsed_spl_token_from_qr_code
    ),
    provider.wallet.publicKey
  );

  const accInfo = await provider.connection.getTokenAccountBalance(
    tokenAcc.address
  );
  console.log(
    "Balance ",
    Number(accInfo.value.amount) / anchor.web3.LAMPORTS_PER_SOL
  );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文