大佬们好,情况是这样的。我有一份非常简单的合约代码。当我用hardhat部署的时候counterAdd可以正常调用,getcounter无法正常调用。
其中有1个全局变量counter,2个方法counterAdd,getcounter。
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.5;
import "hardhat/console.sol";
contract Counter {
uint256 counts;
constructor() {
counts = 0;
}
function getcounter() public view returns (uint256) {
return counts;
}
function addcounter() public {
counts++;
}
}
调用如下
getCntract() {
const provider = new ethers.providers.Web3Provider(
window.ethereum,
);
const signer = provider.getSigner()
const ContractCounter = new ethers.Contract(contractAddress, contractABI, signer)
return ContractCounter
}
async getCount() {
const ContractCounter = this.getCntract()
const result = await ContractCounter.getcounter()
this.count = result.toNumber()
}
报错如下