首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >useDapp的useContractCall抛出“无效合同调用”

useDapp的useContractCall抛出“无效合同调用”
EN

Stack Overflow用户
提问于 2021-10-22 14:14:02
回答 1查看 1K关注 0票数 3

React组件中,我希望读取部署在Rinkeby测试网上的契约中的函数“暂停”。使用"useContractCall",useDapp (https://usedapp.io/)钩子,我在自定义钩子中调用契约函数:

代码语言:javascript
复制
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

何时而不是

代码语言:javascript
复制
const iface = new ethers.Interface([
  "function paused()"
]);

我使用const iface = new ethers.Interface(abi);,我的自定义钩子仍然不能工作,它抛出警告:

代码语言:javascript
复制
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上的指示。

EN

回答 1

Stack Overflow用户

发布于 2021-12-31 07:37:59

我遇到过这个问题。

在我的例子中,被设置为Mainnet,但是浏览器钱包在Rinkeby上。钱包网络改为Mainnet后,问题得到了解决。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69678405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档