9

I am trying to send ETH to a contract function from a web app via metamask and ethers.js. So far I have tried:

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const splitterManager = new ethers.Contract(contract.address, contract.abi, signer);
var overrides = {value: 5}
const result = await splitterManager.newSplitter(addresses, shares, erc20, overrides);
console.log(result);

But I keep getting 'Error: resolver or addr is not configured for ENS name (argument="name", value="", code=INVALID_ARGUMENT, version=contracts/5.2.0)'.

Bruce Jayasinghe
  • 173
  • 1
  • 1
  • 7

4 Answers4

7

You can call the contracts function and pass it an object containing a value key.

contractInstance.testFunction(<any function args>, { value: ethers.utils.parseUnits("1", "ether") });

This would call your contract's function and send that amount of wei to the contract.

function testFunction() public payable {
    // contract code
}
Pang
  • 9,564
  • 146
  • 81
  • 122
CBK
  • 141
  • 1
  • 6
3

If the contract has implemented the receive function, you can send ether to a contract same as sending ether to any other account. Here's a short example:

const accounts = await provider.listAccounts();
const signer = provider.getSigner(accounts[0]);
tx = {
    to: **CONTRACT_ADDRESS**,
    value: ethers.utils.parseEther('2', 'ether')
};
const transaction = await signer.sendTransaction(tx);

Pang
  • 9,564
  • 146
  • 81
  • 122
2
await contractInstance
  .connect(rpcProvider)
  .function({
    value: ethers.utils.parseUnits("1","ether")
  });

this should work

user8555937
  • 2,161
  • 1
  • 14
  • 39
subhajit das
  • 383
  • 3
  • 8
-1

some address is an invalid address it could be the contract.address, the addresses, or some other address

jhonny
  • 805
  • 4
  • 10