Calling Contract Functions
Read data and make transactions on your contract from the connected wallet.
Read Contract Data
Use the name of the function, view, or mapping, and provide any required arguments.
- React
- JavaScript
- Unity
const { contract } = useContract("{{contract_address}}");
const { data: myData, isLoading } = useContractRead(contract, "myFunction");
// read functions will return the data from the contract
const myValue = await contract.call("myReadFunction");
console.log(myValue);
// Place the type of the return value in the <> brackets
var result = await contract.Read<string>("functionName", arg1, arg2);
Write Transactions
Transactions are made using the connected wallet (or the wallet you instantiated the SDK with).
- React
- JavaScript
- Unity
const { contract } = useContract("{{contract_address}}");
const { mutateAsync: myFunctionAsync } = useContractWrite(contract, "myFunction");
const tx = await myFunctionAsync(["argument1", "argument2"]) // Call the function
// write functions will return the transaction receipt
const tx = await contract.call("myWriteFunction", arg1, arg2);
const receipt = tx.receipt;
// Optionally override transaction options
await contract.call("myWriteFunction", arg1, arg2, {
gasLimit: 1000000, // override default gas limit
value: ethers.utils.parseEther("0.1"), // send 0.1 ether with the contract call
});
await contract.Write("functionName", arg1, arg2);