Web3 interaction
Use your web3 library with xRaise connector to interact with web3.
Read contract
Wagmi docs (opens in a new tab)
import { useContractRead } from 'wagmi'
function App() {
const { data, isError, isLoading } = useContractRead({
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
abi: wagmigotchiABI,
functionName: 'getHunger',
})
}
Read multiple contracts
Wagmi docs (opens in a new tab)
xRaise SDK supports multicall for contract reading
import { useContractRead } from 'wagmi'
function App() {
const { data, isError, isLoading } = useContractReads({
contracts: [
{
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
abi: wagmigotchiABI,
functionName: 'getAlive',
},
{
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
abi: wagmigotchiABI,
functionName: 'getBoredom',
},
],
})
}
Write contract
Wagmi docs (opens in a new tab)
import { useContractWrite, usePrepareContractWrite } from 'wagmi'
function App() {
const { data, isLoading, isSuccess, write } = useContractWrite({
address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
abi: wagmigotchiABI,
functionName: 'feed',
})
return (
<div>
<button onClick={() => write()}>Feed</button>
{isLoading && <div>Check Wallet</div>}
{isSuccess && <div>Transaction: {JSON.stringify(data)}</div>}
</div>
)
}
Write multiple contracts
xRaise Wallet supports to batch contract calls into one
const { address } = useAccount();
import { batch } from 'xraise-wagmi-connector/lib/batching';
const batchData = batch({
contracts: [
{
address: payToken.address,
abi: ERC20,
functionName: 'approve',
args: [PAYMENTS_GATEWAY_ADDRESS, cartItemsInfos[0].price],
},
{
address: PAYMENTS_GATEWAY_ADDRESS,
abi: PAYMENTS_GATEWAY_ABI,
functionName: 'buy',
args: [
recipientAddress,
payToken.address,
cartItemsInfos,
[1],
userId
],
},
],
});
const { wait } = await writeContract({
mode: 'recklesslyUnprepared',
address: address!,
abi: BatchFacetABI,
functionName: 'batch',
args: [batchData],
});