0

My calling smart contract method is: Transfer ethers and use alchemy . when clicking the button call payDrink method then show this error:

[Error: Returned error: Unsupported method: eth_sendTransaction. Alchemy does not hold users' private keys. See available methods at https://docs.alchemy.com/alchemy/documentation/apis]

import Web3 from 'web3';
const web3 = new Web3("https://eth-goerli.g.alchemy.com/v2/YPhlCYJ_fLdms1LpSRNs1n6rfcIqGHT9");
    const payDrink = (async () => {
    
    console.log("ethAmount");
    try{
    const contract = new web3.eth.Contract(ContractAbi,contractAddress);
    const transaction = await contract.methods.transfer().send({
      from: '0x9126de09872d12c4f6d417e2cb6061d1ad9e4708',
      value: web3.utils.toWei("0.0001", 'ether'),
  });
    const transactionReciept = await transaction.wait();
    console.log(transactionReciept);}
    catch(err){console.log("eee",err);}
           
    })

Check Screenshoot : alchemy error

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hashmi
  • 21
  • 3

1 Answers1

0

there are many different methods for making web3 objects. by using the network RPC URL you have to make HTTP provide first. Then it passes into the Web3 object.

const provider = new Web3.providers.HttpProvider(Your Network RPC URL);
const web3 = new Web3(provider);

Now this should work perfectly.

Chetan Ukani
  • 116
  • 4