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.