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
- React & React Native
- Other Frameworks
The ThirdwebProvider
handles maintaining the connection state, and allows using all the hooks in the SDK to interact with the blockchain as the connected user.
Here's an example using the Web3Button
component to claim an NFT on a smart contract:
export default function App() {
return (
<ThirdwebProvider
activeChain="goerli"
clientId="YOUR_CLIENT_ID"
supportedWallets={[embeddedWallet()]}
>
<Web3Button
contractAddress="0x..."
action={(contract) => contract.erc721.claim(1)}
>
Claim NFT
</Web3Button>
</ThirdwebProvider>
);
}
To initialize the Contract SDK with your wallet, use the fromWallet
method:
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { EmbeddedWallet } from "@thirdweb-dev/wallet";
const wallet = new EmbeddedWallet();
await wallet.connect();
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
});
const contract = await sdk.getContract("0x...");
await contract.erc721.claim(1);
Full Reference
View everything you can do in the Contract SDK once you have connected your wallet: