'How to send ETH to a contract function with ethers.js?
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)'.
Solution 1:[1]
await contractInstance
.connect(rpcProvider)
.function({
value: ethers.utils.parseUnits("1","ether")
});
this should work
Solution 2:[2]
some address is an invalid address it could be the contract.address, the addresses, or some other address
Solution 3:[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 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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user8555937 |
Solution 2 | jhonny |
Solution 3 | Jorge M. Londoño P. |