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