nearprotocol - 进行跨合约调用时超出预付 gas 错误
问题描述
这是我的跨合约调用代码:
const NO_DEPOSIT: Balance = 0;
const GAS: Gas = 25_000_000_000_000;
#[ext_contract(ext_erc20)]
pub trait ExtErc20 {
fn get_total_supply(&self) -> U128;
}
函数调用:
pub fn get_total_supply_erc20(&self, erc20_id: AccountId) -> Promise {
ext_erc20::get_total_supply(&erc20_id, NO_DEPOSIT, GAS)
}
Javascript代码:
const data = await nearvar.contract.get_total_supply_erc20({"erc20_id": "dev-1608541613194-2197959"})
console.log(data)
它给出“超过预付气体”错误。我也尝试了不同的气体值,但没有奏效。
可替代代币,获取总供应量:
pub fn get_total_supply(&self) -> U128 {
self.total_supply.into()
}
解决方案
请检查一下:我需要创建一个工作示例以确定,但我认为问题如下:
请注意,您可能会收到“Exceeded the prepaid gas”错误,几乎没有执行。假设您get_total_supply_erc20
使用 50TGas 限制从客户端进行调用,并且在调用的 fn 代码中您有:
const GAS = 51*TGAS;
pub fn get_total_supply_erc20(&self, erc20_id: AccountId) -> Promise {
ext_erc20::get_total_supply(&erc20_id, NO_DEPOSIT, GAS)
}
你会得到一个“Exceeded the prepaid gas”错误,但不是因为消耗,而是因为 Promise 引擎无法为 promise 调用预留 51*Tgas,因为客户端调用只有 50Tgas 限制。两种功能的实际消耗是 2 还是 3 TGas 都没有关系。
推荐阅读
- spring - 带有数据 jpa 的 Spring Boot 在启动时出错
- setuptools - 如何在没有安装的情况下检查 setup.py 中软件包的兼容性?
- html - 我可以阻止 Youtube 嵌入 iframe 在与之交互时滚动到视图中吗?它打破了我的手风琴
- rxjs - concatMap 中发生错误时如何不触发“完成”处理程序?
- json - 将 PowerShell JSON 转换为 CSV 文件
- java - 这个极小极大算法有什么问题
- android - 是否可以使用 Firebase 制作单独的 InkWell 按钮?扑
- arrays - 如何在不使用 useState 更改 React Native 中的位置的情况下更新数组元素的值?
- reactjs - 更改日视图的 fullCalendar 标题日期格式
- vue.js - Vue 视频背景无法启动