【发布时间】:2021-10-22 14:14:02
【问题描述】:
在 React 组件中,我想读取部署在 Rinkeby 测试网上的合约中“暂停”的功能。使用 useDapp (https://usedapp.io/) 钩子“useContractCall”,我在自定义钩子中调用合约函数:
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 上的说明进行操作。
【问题讨论】:
标签: node.js reactjs solidity web3 ethers.js