3

Update (08 July 2023) : From node_modules/ethers/lib.esm/contract/contract.js, I found the error message (the assert part).

 const send = async function (...args) {
        const runner = contract.runner;
        assert(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" });
        const tx = await runner.sendTransaction(await populateTransaction(...args));
        const provider = getProvider(contract.runner);
        // @TODO: the provider can be null; make a custom dummy provider that will throw a
        // meaningful error
        return new ContractTransactionResponse(contract.interface, provider, tx);
    };

And the canSend is:

function canSend(value) {
    return (value && typeof (value.sendTransaction) === "function");
}

So basically, contract.runner should be a function type. However, in my case, contract.runner is a string (address type).

Even more strange thing is that I put a console.log right before execute a smart contract function whether the runner has function or not. console.log('myContract.runner.sendTransaction :', myContract.runner.sendTransaction); This properly prints a function.

I am not sure where & why contract.runner is a string. Anyone knows the reason?


The original post: I am facing an error error: contract runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.6.0) when I execute pay() from Frontend. I am not sure where to start debugging. It's running on my local with hardhat and Metamask.

const setContracts = async () => { // #1. I run this first.
  const provider = new ethers.BrowserProvider(ethereum);
  const signer = await provider.getSigner();
  const myContract: ethers.Contract = new ethers.Contract(myContractAddress, contractABI, 
  signer);

  setMyContract(myContract);
}

const pay = async() => { // #2. then run this one 
    const amount = ethers.parseUnits("1.0", 18);
    console.log('myContract.runner.sendTransaction :', myContract.runner.sendTransaction); // <- function properly printed
    myContract
      .connect(connectedAccount) // #3. This account has 1,000 ETH
      .donate(targetAddress, {value: amount});  // #4. error: contract runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.6.0)
 
  };

Any advice will be appreciated.

5
  • This should solve the issue Jul 7, 2023 at 11:23
  • @ZartajAfser Thanks for the comment but I am already using "signer" when I get an instance of the contract and not provider.
    – Téwa
    Jul 7, 2023 at 11:37
  • Did you check if the signer, provider, and contract everything is initialized correctly, by console logging them? Jul 7, 2023 at 11:39
  • @ZartajAfser I believe yes and even some transaction which update storage variable work. Only sending ETH not working for the moment.
    – Téwa
    Jul 7, 2023 at 12:16

1 Answer 1

0

The problem was .connect(connectedAccount) when I removed this code, the runner object contains sendTransaction.

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.