0

When I try to send EHT using the below code, the transaction executes, but 0 EHT is sent:

const getEthereumContract = () => {
  // const provider = new ethers.provider.Web3Provider(ethereum);
  const provider = new ethers.BrowserProvider(window.ethereum);
  const signer = provider.getSigner();
  const transactionContract = new ethers.Contract(
    contractAddress,
    contractABI,
    signer
  );

console.log({ provider, signer, transactionContract });

return transactionContract; }; const sendTransaction = async () => { try { if (!ethereum) return alert("Please install metamsak"); const { addressTo, amount, keyword, message } = formData; // getEthereumContract(); const transactionContract = getEthereumContract(); // const parsedAmount = ethers.utils.parseEther(amount);

  const parsedAmount = ethers.parseEther(amount);
  console.log(
    " ~ file: TransactionContext.jsx:71 ~ sendTransaction ~ amount:",
    amount
  );

  await ethereum.request({
    method: "eth_sendTransaction",
    params: [
      {
        from: currentAccount,
        to: addressTo,
        gas: "0x5208",
        value: parsedAmount._hex,
      },
    ],
  });

I see the follwing error in the browser console:

Error: contract runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.6.0)
    at makeError (errors.ts:677:21)
    at assert (errors.ts:694:25)
    at send (contract.ts:288:9)
    at Proxy.addToBlockchain (contract.ts:330:22)
    at sendTransaction (TransactionContext.jsx:88:57)
TransactionContext.jsx:104 Uncaught (in promise) Error: No ethereum objsct.
    at sendTransaction (TransactionContext.jsx:104:13)
Foxxxey
  • 4,307
  • 1
  • 6
  • 22

2 Answers2

1

In ethers v6, provider.getSigner(); returns a promise (i don't really know why, that's confusing, unnecessary and would only lead to that kind of errors) . You're trying to use a promise as your signer. Add an await. Also, i formatted your code for you. Next time you ask a question, make sure to surround your code blocks by 3 backticks ( ``` ) before and after.

like this
Foxxxey
  • 4,307
  • 1
  • 6
  • 22
-1

If you are trying to call a function in your contract you should do;

const provider = new ethers.BrowserProvider(window.ethereum); 
const signer = provider.getSigner(); 
const transactionContract = new ethers.Contract( contractAddress, contractABI, signer );

await transactionContract.method(args, {value:12345})

method is to be replace by the method you want to call.

even if you want to send a raw transaction, you still have to work with a wallet or a provider.

MadeInDreams
  • 1,500
  • 1
  • 9
  • 19