reactjs - methods.myFunction().call() throws 返回值是无效的,它是否耗尽了 Gas?错误
问题描述
我正在使用“web3”:“1.0.0-beta.26”并收到以下错误...
返回值无效,它是否用尽了 Gas?如果您没有为从中检索数据的合约使用正确的 ABI、从不存在的块号请求数据或查询未完全同步的节点,您也可能会看到此错误。
我已经重新运行 truffle migrate --reset 并使用生成的地址作为 TODO_LIST_ADDRESS 但我仍然收到上面的错误
有人遇到过这个问题并且知道如何解决吗?谢谢
应用程序.js
class App extends Component {
constructor(props) {
super(props);
this.state = {
account: "test",
taskCount: 0
};
}
componentDidMount() {
this.loadBlockchainData();
}
loadBlockchainData = async () => {
const ethereum = window.ethereum;
ethereum.autoRefreshOnNetworkChange = false;
const web3 = window.web3;
const web3Instance = new Web3(ethereum);
const enabledWeb3 = await ethereum.enable();
const accounts = await web3Instance.eth.getAccounts();
const accountAddress = await accounts[0];
this.setState({ account: accountAddress });
const todoList = new web3Instance.eth.Contract(
TODO_LIST_ABI,
TODO_LIST_ADDRESS
);
console.log("todoList ", todoList);
//! ERROR
const taskCount = await todoList.methods.taskCount().call();
console.log("taskCount ", taskCount);
this.setState({ taskCount });
};
render() {
return (
<div className="container">
<h1>Hey World</h1>
<p>Your Account: {this.state.account}</p>
<p>Task Count: {this.state.taskCount}</p>
</div>
);
}
}
export default App;
配置.js
export const TODO_LIST_ADDRESS = "0xb0D64f6C317448efa56A33678d718Fd715DAeddd";
export const TODO_LIST_ABI = [
{
inputs: [],
payable: false,
stateMutability: "nonpayable",
type: "constructor"
},
{
constant: true,
inputs: [],
name: "taskCount",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
name: "tasks",
outputs: [
{
internalType: "uint256",
name: "id",
type: "uint256"
},
{
internalType: "string",
name: "content",
type: "string"
},
{
internalType: "bool",
name: "completed",
type: "bool"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{
internalType: "string",
name: "_content",
type: "string"
}
],
name: "createTask",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
}
];
解决方案
推荐阅读
- python-3.x - 使用 selenium 从 glassdoor 抓取数据
- c# - 视图内的线性布局 (Xamarin.Android)
- javascript - 始终在同一选项卡中打开锚点 href
- python - 如何循环问题并限制输入?
- c++ - 使用 operator new/delete 的 align_val_t 重载总是安全的吗?
- javascript - 即使没有内容更改或文档没有更改,也会调用 vscode.workspace.onDidChangeTextDocument()
- java - 在jtable中选择一行的值时,它向我显示了上一个值
- java - 如何在 Java 中四舍五入到下一个一百
- .htaccess - .htaccess 和 session 不能正常工作
- roku - 除了 Observefield 之外,Roku 中的自定义回调