在React组件中,我希望读取部署在Rinkeby测试网上的契约中的函数“暂停”。使用"useContractCall",useDapp (https://usedapp.io/)钩子,我在自定义钩子中调用契约函数:
import { ethers } from "ethers";
import { useContractCall } from "@usedapp/core";
import { contractAddress } from '../../index.js'
const iface = new ethers.Interface([
"function paused()"
]);
export function usePaused() {
const [paused] = useContractCall({
abi: iface,
address: contractAddress,
method: 'paused',
args: [],
}) ?? [];
return paused;
}它抛出一个错误TypeError: ethers__WEBPACK_IMPORTED_MODULE_0__.ethers.utils.Interface is not a constructor
何时而不是
const iface = new ethers.Interface([
"function paused()"
]);我使用const iface = new ethers.Interface(abi);,我的自定义钩子仍然不能工作,它抛出警告:
Invalid contract call: address=0x...contract_address... method=paused args=
at RenderButton (http://localhost:3001/static/js/main.chunk.js:1961:70)我做错什么了?我遵循https://usedapp.readthedocs.io/en/latest/guide.html#custom-hooks上的指示。
发布于 2021-12-31 07:37:59
我遇到过这个问题。
在我的例子中,被设置为Mainnet,但是浏览器钱包在Rinkeby上。钱包网络改为Mainnet后,问题得到了解决。
https://stackoverflow.com/questions/69678405
复制相似问题