【问题标题】:Error: sending a transaction requires a signer while ccalling aggregate function of Multicall Contract ethereum错误:在调用 Multicall Contract ethereum 的聚合函数时发送交易需要签名者
【发布时间】:2021-03-31 21:30:41
【问题描述】:

index.js:1 Failed to fetch multicall chunk [{…}] 1 错误:发送交易需要签名者(operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=contracts/5.0.2)

多重调用合约地址 - https://etherscan.io/address/0xeefba1e63905ef1d7acba5a8513c70307c1ce441#writeContract

在 Uniswap 接口中工作,但在我的代码中抛出错误,我不知道出了什么问题

【问题讨论】:

  • 您需要提供代码和具体问题

标签: javascript reactjs ethereum ether etherscan


【解决方案1】:

我有类似的情况,参考 uniswap-interface 代码使用@web3-react

@web3-react 基于ethers.js,我们必须使用signer 执行状态改变方法。 我发布了一个我解决的示例。

const { library, account } = useActiveWeb3React();

const contract = getContract(
      CONTRACT_ADDRESS,
      abi,
      library
    );
const signer = contract.connect(library.getSigner());
signer.someStateChangingMethods();

这可能会对您有所帮助。 https://docs.ethers.io/v5/getting-started/#getting-started--writing

【讨论】:

    【解决方案2】:

    你必须提供一个签名者来执行solidity方法。

    您可以从您的 web3 提供商处获得签名者。

    您可以像这样将签名者绑定到合同

    import Contract from './artifacts/contracts/Contract.sol/Contract.json'
    const contractDeployedAddress = "0xblah";
    
    const provider = new ethers.providers.Web3Provider(window.ethereum)
    const signer = provider.getSigner();
    const contract = new ethers.Contract(contractDeployedAddress, Contract.abi, signer)
    
    await contract.someMethodThatRequiresSigning();
    

    【讨论】:

      猜你喜欢
      • 2022-06-18
      • 2022-08-13
      • 2017-11-29
      • 2018-07-28
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 2018-11-04
      相关资源
      最近更新 更多