You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Radix Scrypto 0.9.0测试:如何在Rust中查询账户代币余额?

在Scrypto 0.9.0中查询账户余额的替代方案

在Scrypto 0.9.0版本中,Account组件的balance方法已被移除,你可以通过以下两种方式查询指定账户的代币余额:

1. 通过Manifest调用账户的balance_of方法

使用ManifestBuilder调用账户组件的balance_of方法获取余额,示例代码如下:

let manifest = ManifestBuilder::new()
    .call_method(compo_addr, "balance_of", manifest_args!(resource_addr))
    .build();

// 执行manifest并提取返回的余额结果
let receipt = Runtime::execute_manifest(manifest, vec![]);
let balance: Decimal = receipt.expect_commit().output(0);

2. 直接使用测试框架的Runtime工具

在测试场景下,无需构建Manifest,直接调用Runtime::account_balance方法即可快速查询:

let balance = Runtime::account_balance(compo_addr, resource_addr);

内容的提问来源于stack exchange,提问作者Russo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 18:22:00