Skip to main content

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.

const { contract } = useContract("{{contract_address}}");
const { data: myData, isLoading } = useContractRead(contract, "myFunction");

Write Transactions

Transactions are made using the connected wallet (or the wallet you instantiated the SDK with).

const { contract } = useContract("{{contract_address}}");
const { mutate: myFunction, isLoading, error } = useContractWrite(contract, "myFunction");
myFunction(["argument1", "argument2"]) // Call the function
// Alternatively, you can get an async function to call
const { mutateAsync: myFunctionAsync } = useContractWrite(contract, "myFunction");
// tx contains a receipt of the transaction
const tx = await myFunctionAsync(["argument1", "argument2"]) // Call the function