首页 > 解决方案 > 进行跨合约调用时超出预付 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()
}

代码文件

标签: nearprotocol

解决方案


请检查一下:我需要创建一个工作示例以确定,但我认为问题如下:

请注意,您可能会收到“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 都没有关系。


推荐阅读