Do anything crosschain by specifying txs to be executed on the target chain.
You can supply an object of parameters listed below:
Parameter | Description | Required | Example |
---|---|---|---|
toChainId | The chain id to interact with | true | 1 |
wallet | A valid WalletClient from viem or a ReservoirWallet generated from an adapter. Learn more about adapters. | true | Refer to viem's documentation on WalletClients_ |
txs | An array of either transaction objects (made up of a to, data and value properties) or viem request objects returned from viem's simulateContract function. A code snippet is provided below which show an example of this in conjunction with the Zora protocol SDK | true | [{to: "0x30385bce01da4b415cae1db21d41e9f6eab3ba50", value: "1000000", data: "0x" }] or [SIMULATE_REQUEST] |
onProgress | Callback to update UI state as execution progresses. Can also be used to get the transaction hash for a given step item. | true | (steps) => { console.log(steps) } |
chainId | Override the current active chain | false | 1 |
precheck | A boolean indicating whether to just get back the steps/path and not to execute them. This is useful for checking if marketplace approval is required before iterating over the steps. | false | true |
Example
import { getClient, Execute } from "@reservoir0x/reservoir-sdk";
import { createWalletClient, http } from 'viem'
...
wallet = createWalletClient({
account: address,
transport: http()
})
getClient().actions.call({
toChainId: 8453,
txs: [{to: "0x30385bce01da4b415cae1db21d41e9f6eab3ba50", value: "1000000", data: "0x"}]
wallet: wallet,
onProgress: (steps) => {
console.log(steps)
},
})
//@ts-ignore
import "./styles.css";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import { useReservoirClient } from "@reservoir0x/reservoir-kit-ui";
import { useCallback } from "react";
import { ReservoirClientActions } from "@reservoir0x/reservoir-sdk";
import { createPublicClient, http, WriteContractParameters } from "viem";
import { useWalletClient } from "wagmi";
import { createMintClient } from "@zoralabs/protocol-sdk";
import { base, zora } from "viem/chains";
export default function App() {
const sdkClient = useReservoirClient();
const { data: wallet } = useWalletClient({
chainId: base.id,
});
const customMint = useCallback(async () => {
if (!wallet || !wallet.account?.address) {
throw "A wallet is required to mint!";
}
if (!sdkClient) {
throw "Reservoir SDK not initialized";
}
const mintClient = createMintClient({ chain: zora });
const publicClient = createPublicClient({
chain: zora,
transport: http(),
});
const prepared = await mintClient.makePrepareMintTokenParams({
// token to mint
tokenAddress: "0x03e4f2838b2e821d2117a78a278c4e3166d97339",
tokenId: "4",
mintArguments: {
// address that will receive the token
mintToAddress: wallet.account.address,
// quantity of tokens to mint
quantityToMint: 1,
// comment to include with the mint
mintComment: "Cross-Chain Minting via Reservoir!",
},
// account that is to invoke the mint transaction
minterAccount: wallet.account.address,
});
// simulate the transaction and get any validation errors
const { request } = await publicClient.simulateContract(prepared);
const actions = sdkClient.actions as ReservoirClientActions;
actions.call({
toChainId: zora.id,
txs: [request],
chainId: base.id,
wallet,
onProgress: () => {},
});
}, [sdkClient, wallet]);
return (
...
<button
className="button"
style={{ marginTop: 16, marginRight: "auto" }}
onClick={customMint}
>
Custom Mint + Zora SDK
...
);
}