什么是错误错误:返回错误:调用区块链数据时执行恢复以及如何解决?
Posted
技术标签:
【中文标题】什么是错误错误:返回错误:调用区块链数据时执行恢复以及如何解决?【英文标题】:What is error Error: Returned error: execution reverted when calling blockchain data and how to fix it? 【发布时间】:2021-09-26 18:23:33 【问题描述】:我正在使用 React 并使用 useEffect 从 App.js 中的区块链获取一些数据并将其存储在 useState 但是当要解决承诺时,它会捕获此错误:
error Error: Returned error: execution reverted
at Object.ErrorResponse (errors.js:28)
at index.js:303
at XMLHttpRequest.request.onreadystatechange (index.js:98)
这是 App.js 中的代码
const data = mainnet.FairLaunch.pools.map((pool) =>
const loadingStakingData = async () =>
const stakedValue = await getStakeValue(pool);
console.log('Loop staking data', stakedValue); // logging correctly
return stakedValue;
;
return loadingStakingData();
);
Promise.all(data)
.then((values) =>
console.log('values', values); // error breaks app before console.log is triggered
setStakingData(values);
)
.catch((error) => console.error('error', error));
这是查询区块链数据的 getStakeValue() 代码:
export async function getStakeValue(param = )
const vault = getWeb3VaultContract(param.address);
const totalSupply = parseInt(await vault.methods.totalSupply().call());
const totalToken = parseInt(await vault.methods.totalToken().call());
//getFairLaunch gets the address according to the environment prod or dev
const balance = await vault.methods.balanceOf(getFairLaunch()).call();
let stakeValue = (balance * 100 * totalToken) / totalSupply;
console.log('stakeValue: ' , typeof stakeValue); //number
console.log('stakeValue: ' , parseInt(stakeValue)); // log correctly
return stakeValue;
这是具有以下功能的 ABI:
export default [
"inputs": [],
"name": "totalToken",
"outputs": [
"internalType": "uint256",
"name": "",
"type": "uint256"
],
"stateMutability": "view",
"type": "function"
,
"inputs": [],
"name": "totalSupply",
"outputs": [
"internalType": "uint256",
"name": "",
"type": "uint256"
],
"stateMutability": "view",
"type": "function"
,
"inputs": [
"internalType": "address",
"name": "account",
"type": "address"
],
"name": "balanceOf",
"outputs": [
"internalType": "uint256",
"name": "",
"type": "uint256"
],
"stateMutability": "view",
"type": "function"
,
];
知道这个错误是什么以及如何修复它吗?
【问题讨论】:
【参考方案1】:遇到同样的问题..
更改合约地址和 abi 后。
批准失败..
【讨论】:
为什么这是被接受的答案?但是如何解决这个问题?以上是关于什么是错误错误:返回错误:调用区块链数据时执行恢复以及如何解决?的主要内容,如果未能解决你的问题,请参考以下文章
在视图/只读区块链函数上调用 ethers web3js 时出现气体限制错误