Skip to content

Instantly share code, notes, and snippets.

@matthope1
Created December 24, 2021 17:15
Show Gist options
  • Save matthope1/e5618cbe5aff4f10fbde00f353921800 to your computer and use it in GitHub Desktop.
Save matthope1/e5618cbe5aff4f10fbde00f353921800 to your computer and use it in GitHub Desktop.
Ethers.js - How to add value to smart contract function call
# To add funds to a function call you'll first need to have access to a contract instance
const contractInstance = new ethers.Contract(contractAddress, contractABI, signer)
# Then you'll need to create an object that will be passed into the smart contract as a parameter
# This object needs a key called value
# value needs to be a string representing wei (10^18 wei = 1 ether)
const overrides = {
value = "10000"
}
# Call the function on your smart contract & pass in overrides
# This function should be payable
cont txn = await contract.myFunction(arg1, arg2, overrides)
# This function call will start the transaction with the amount specified as value in our overrides object
@matthope1
Copy link
Author

TYPO line 13, cont -> const

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment