Skip to main content

Interact With The Blockchain

One connected, embedded wallets can be used alongside the Contract SDK to interact with the blockchain.

View all of the wallet actions available on a wallet instance.

Initialize the SDK With Your Wallet

If you are working in React, React Native or Unity and have connected your wallet with the Connect Wallet Component you can skip this step - your wallet can already be used with the SDKs.

To initialize the TypeScript SDK with your wallet, use the fromWallet method:

import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { EmbeddedWallet } from "@thirdweb-dev/wallet";

const wallet = new EmbeddedWallet();

const sdk = ThirdwebSDK.fromWallet(wallet, "ethereum", {
clientId: "YOUR_CLIENT_ID", // Use client id if using on the client side, get it from dashboard settings
secretKey: "YOUR_SECRET_KEY", // Use secret key if using on the server, get it from dashboard settings
});

Execute a Write Function

const contract = await sdk.getContract("0x...");
const data = await contract.call(
"myFunctionName", // Name of your function as it is on the smart contract
// Arguments to your function, in the same order they are on your smart contract
[
"arg1", // e.g. Argument 1
"arg2", // e.g. Argument 2
],
);

Get The Signer/Address

//Get the wallet signer (Wallet SDK)
const signer = await wallet.getSigner();

//Get the wallet address (Wallet SDK)
const address = await wallet.getAddress();

View The Owned NFTs

// Address of the wallet to get the NFTs of
const contract = await sdk.getContract("0x...");
const address = wallet.getAddress(); // Optional - Defaults to the connected wallet
const nfts = await contract.erc721.getOwned(address);

Full Reference

View everything you can do in the Contract SDK once you have connected your wallet: