0

This is my method of obtaining the signer

async function getSigner() { if (window.ethereum) { await window.ethereum.enable() provider = new ethers.providers.Web3Provider(window.ethereum) // console.log(window.ethereum) console.log(provider) const signer = provider.getSigner() console.log(signer) setSigner(signer) const contract = new ethers.Contract(daiAddress, daiAbi, provider) console.log(contract) setDaiContract(contract) } }

Error: sending a transaction requires a signer (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=contracts/5.7.0)

1
  • async function getSigner() { if (window.ethereum) { await window.ethereum.enable() provider = new ethers.providers.Web3Provider(window.ethereum) // console.log(window.ethereum) console.log(provider) const signer = provider.getSigner() console.log(signer) setSigner(signer) const contract = new ethers.Contract(daiAddress, daiAbi, provider) console.log(contract) setDaiContract(contract) } }
    – eae
    Jun 28, 2023 at 6:15

1 Answer 1

0

The provider can be used only for viewing, and the signer is required if the contract state variables need to be modified.

const contract = new ethers.Contract(daiAddress, daiAbi, signer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.