我正在使用“ web3”:“ 1.0.0-beta.26”,并出现以下错误...
返回的值无效,是否用完了?如果您没有对要使用的合同使用正确的ABI,或者从不存在的块号中请求数据或查询未完全同步的节点,也可能会看到此错误。 >
我已经重新运行松露迁移--reset,并使用了生成的地址作为TODO_LIST_ADDRESS,但是上面仍然出现错误
任何人以前都遇到过这个问题,知道如何解决吗?谢谢
App.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;
config.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"
}
];