### .NET Package Installation Source: https://portal.thirdweb.com/dotnet/getting-started Installs the Thirdweb SDK via the NuGet package manager. ```bash dotnet add package Thirdweb ``` -------------------------------- ### Install the contracts package using Forge Source: https://portal.thirdweb.com/tokens/build/get-started Command to install the thirdweb contracts package into an existing Forge project. ```bash forge install https://github.com/thirdweb-dev/contracts ``` -------------------------------- ### Install Example Source: https://portal.thirdweb.com/llms-full.txt Example usage of install. ```typescript import { RoyaltyERC1155 } from "thirdweb/modules"; const transaction = RoyaltyERC1155.install({ contract: coreContract, account: account, params: { royaltyRecipient: ..., royaltyBps: ..., transferValidator: ... }, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### Example of inheriting and using a base contract (ERC721Base) Source: https://portal.thirdweb.com/tokens/build/get-started A Solidity smart contract example demonstrating inheritance from ERC721Base and implementing its constructor. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@thirdweb-dev/contracts/base/ERC721Base.sol"; contract MyNFT is ERC721Base { constructor( address _defaultAdmin, string memory _name, string memory _symbol, address _royaltyRecipient, uint128 _royaltyBps ) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {} } ``` -------------------------------- ### install example Source: https://portal.thirdweb.com/llms-full.txt Example of how to install the OpenEditionMetadataERC721 module. ```typescript import { OpenEditionMetadataERC721 } from "thirdweb/modules"; const transaction = OpenEditionMetadataERC721.install({ contract: coreContract, account: account, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### Install thirdweb and its React Native adapter packages Source: https://portal.thirdweb.com/react-native/v5/getting-started Installs the necessary thirdweb packages for React Native development. ```bash npx expo install thirdweb @thirdweb-dev/react-native-adapter ``` -------------------------------- ### Example of inheriting base contracts and extensions (ERC721Base and Permissions) Source: https://portal.thirdweb.com/tokens/build/get-started A Solidity smart contract example demonstrating inheritance from both ERC721Base and the Permissions extension. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@thirdweb-dev/contracts/base/ERC721Base.sol"; import "@thirdweb-dev/contracts/extension/Permissions.sol"; contract MyNFT is ERC721Base, Permissions { constructor( address _defaultAdmin, string memory _name, string memory _symbol, address _royaltyRecipient, uint128 _royaltyBps ) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {} } ``` -------------------------------- ### install Example Source: https://portal.thirdweb.com/llms-full.txt Example of installing the RoyaltyERC721 module on a core contract. ```typescript import { RoyaltyERC721 } from "thirdweb/modules"; const transaction = RoyaltyERC721.install({ contract: coreContract, account: account, params: { royaltyRecipient: ..., royaltyBps: ..., transferValidator: ... }, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### Example usage of install Source: https://portal.thirdweb.com/llms-full.txt Shows how to install the MintableERC20 module on a core contract. ```typescript import { MintableERC20 } from "thirdweb/modules"; const transaction = MintableERC20.install({ contract: coreContract, account: account, params: { primarySaleRecipient: ..., }, }); await sendTransaction({ transaction, account, }); ``` ```typescript function install(options: { account: Account; contract: Readonly; params: EncodeBytesOnInstallParams & { publisher?: string }; }): PreparedTransaction; ``` -------------------------------- ### Example Source: https://portal.thirdweb.com/llms-full.txt Example of getting the default light theme. ```typescript const defaultLightTheme = lightTheme(); ``` -------------------------------- ### install example Source: https://portal.thirdweb.com/llms-full.txt Installs the MintableERC721 module on a core contract. ```typescript import { MintableERC721 } from "thirdweb/modules"; const transaction = MintableERC721.install({ contract: coreContract, account: account, params: { primarySaleRecipient: ..., }, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### SequentialTokenIdERC1155.install Example Source: https://portal.thirdweb.com/llms-full.txt Example of installing the SequentialTokenIdERC1155 module. ```typescript import { SequentialTokenIdERC1155 } from "thirdweb/modules"; const transaction = SequentialTokenIdERC1155.install({ contract: coreContract, account: account, params: { startTokenId: ..., }, }); await sendTransaction({ transaction, account, }); ``` ```typescript function install(options: { account: Account; contract: Readonly; params: EncodeBytesOnInstallParams & { publisher?: string }; }): PreparedTransaction; ``` -------------------------------- ### Complete Example: Setup and Use Session Key with ERC-7702 Source: https://portal.thirdweb.com/wallets/session-keys This comprehensive example shows the full process of setting up a session key using ERC-7702, including creating the smart EOA, granting permissions, and executing a transaction. ```typescript import { createThirdwebClient, getContract, sendTransaction, prepareTransaction, } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { inAppWallet, createSessionKey, } from "thirdweb/wallets/in-app"; import { Engine } from "thirdweb/engine"; async function setupSessionKeyWith7702() { // Configuration const client = createThirdwebClient({ clientId: "your-client-id", secretKey: "your-secret-key", }); const sessionKeyAccountAddress = "0x..."; // Your session key address (server wallet) try { // Step 1: Create 7702 Smart EOA const wallet = inAppWallet({ executionMode: { mode: "EIP7702", sponsorGas: true, }, }); const account = await wallet.connect({ chain: sepolia, client: client, strategy: "google", }); console.log("Upgraded EOA created:", account.address); // Step 2: Get account contract const accountContract = getContract({ address: account.address, chain: sepolia, client: client, }); // Step 3: Create session key const sessionTx = await sendTransaction({ account: account, transaction: createSessionKey({ account: account, contract: accountContract, sessionKeyAddress: sessionKeyAccountAddress, durationInSeconds: 86400, // 1 day grantFullPermissions: true, }), }); console.log("Session key created:", sessionTx.transactionHash); // Step 4: Use the session key with Engine const serverWallet = Engine.serverWallet({ address: sessionKeyAccountAddress, chain: sepolia, client: client, executionOptions: { type: "EIP7702", sessionKeyAddress: sessionKeyAccountAddress, accountAddress: account.address, }, }); // Execute a transaction with the session key const tx = await sendTransaction({ account: serverWallet, transaction: prepareTransaction({ chain: sepolia, client: client, to: "0x...", // Target address value: 0n, }), }); console.log("Transaction successful:", tx.transactionHash); return tx; } catch (error) { console.error("Error:", error); throw error; } } // Execute the function setupSessionKeyWith7702() .then((tx) => console.log("Done!", tx.transactionHash)) .catch((error) => console.error("Failed:", error)); ``` -------------------------------- ### TransferableERC20.install Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to install the TransferableERC20 module on a core contract. ```typescript import { TransferableERC20 } from "thirdweb/modules"; const transaction = TransferableERC20.install({ contract: coreContract, account: account, }); await sendTransaction({ transaction, account, }); ``` ```typescript function install(options: { account: Account; contract: Readonly; params?: { publisher?: string }; }): PreparedTransaction; ``` -------------------------------- ### Setup the ThirdwebProvider Source: https://portal.thirdweb.com/react/v5/getting-started Wrap your application with ThirdwebProvider at the root to manage state like active wallet and chain. ```tsx // src/main.tsx import { ThirdwebProvider } from "thirdweb/react"; function Main() { return ( ); } ``` -------------------------------- ### Example Source: https://portal.thirdweb.com/llms-full.txt Example of getting a transaction store. ```typescript import { getTransactionStore } from "thirdweb/transaction"; const store = getTransactionStore("0x..."); store.subscribe((transactions) => { console.log(transactions); }); ``` -------------------------------- ### getAll Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get all proposals from a Vote contract. ```typescript import { getAll } from "thirdweb/extension/getAll"; const allProposals = await getAll({ contract }); ``` ```typescript function getAll( options: BaseTransactionOptions ): Promise>; ``` -------------------------------- ### BatchMetadataERC721.install Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to install the BatchMetadataERC721 module on a core contract. ```typescript import { BatchMetadataERC721 } from "thirdweb/modules"; const transaction = BatchMetadataERC721.install({ contract: coreContract, account: account, }); await sendTransaction({ transaction, account, }); ``` ```typescript function install(options: { account: Account; contract: Readonly; params?: { publisher?: string }; }): PreparedTransaction; ``` -------------------------------- ### Install Published Extension Source: https://portal.thirdweb.com/llms-full.txt Example of how to install a published extension on a dynamic contract. ```typescript import { installPublishedExtension } from "thirdweb/dynamic-contracts"; const transaction = installPublishedExtension({ client, chain, account, contract, extensionName: "MyExtension", publisherAddress: "0x...", }); await sendTransaction({ transaction, account }); ``` ```typescript function installPublishedExtension( options: InstallPublishedExtensionOptions, ): PreparedTransaction; ``` -------------------------------- ### Setup Source: https://portal.thirdweb.com/wallets/session-keys First, let's set up the necessary imports and configuration: ```typescript import { createThirdwebClient, getContract, sendTransaction, prepareTransaction, } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { inAppWallet, createSessionKey, } from "thirdweb/wallets/in-app"; // Configure your client const client = createThirdwebClient({ clientId: "your-client-id", secretKey: "your-secret-key", // Only use in server environments }); // Your session key account address const sessionKeyAccountAddress = "0x..."; // Replace with your session key address (server wallet) ``` -------------------------------- ### Set up the Client, Provider and ConnectButton Source: https://portal.thirdweb.com/wallets/quickstart Initialize the SDK with your client ID, wrap your application with the ThirdwebProvider, and add a ConnectButton. ```typescript import { createThirdwebClient } from "thirdweb"; import { ThirdwebProvider, ConnectButton } from "thirdweb/react"; export const client = createThirdwebClient({ clientId: }); export default function App() { return ( ); } ``` -------------------------------- ### Example usage of TransferableERC721.install Source: https://portal.thirdweb.com/llms-full.txt An example demonstrating how to install the TransferableERC721 module on a core contract. ```typescript import { TransferableERC721 } from "thirdweb/modules"; const transaction = TransferableERC721.install({ contract: coreContract, account: account, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### Complete Example Source: https://portal.thirdweb.com/engine/v3/guides/session-keys This comprehensive example demonstrates the entire process of setting up and executing a transaction with a session key, including account generation, smart wallet configuration, session key verification, and transaction execution. ```typescript import { generateAccount, smartWallet, sendTransaction, getContract, createThirdwebClient, } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { getAllActiveSigners } from "thirdweb/extensions/erc4337"; import { Engine } from "thirdweb/engine"; async function executeTransactionWithSessionKey() { // Configuration const client = createThirdwebClient({ clientId: "your-client-id", secretKey: "your-secret-key", }); const sessionKeyAccountAddress = "0x..."; // Your session key address const targetAddress = "0x..."; // Target address for the final transaction try { // Step 1: Create personal account const personalAccount = await generateAccount({ client }); // Step 2: Configure smart wallet const smart = smartWallet({ chain: sepolia, sessionKey: { address: sessionKeyAccountAddress, permissions: { approvedTargets: "*", }, }, sponsorGas: true, }); // Step 3: Connect smart account const smartAccount = await smart.connect({ client, personalAccount, }); // Step 4: Verify session key const signers = await getAllActiveSigners({ contract: getContract({ address: smartAccount.address, chain: sepolia, client, }), }); const isSessionKeyActive = signers .map((s) => s.signer) .includes(sessionKeyAccountAddress); if (!isSessionKeyActive) { throw new Error("Session key is not active"); } // Step 5: Create server wallet const serverWallet = Engine.serverWallet({ address: sessionKeyAccountAddress, chain: sepolia, client, executionOptions: { entrypointVersion: "0.6", signerAddress: sessionKeyAccountAddress, smartAccountAddress: smartAccount.address, type: "ERC4337", }, vaultAccessToken: process.env.VAULT_TOKEN as string, }); // Step 6: Execute transaction const tx = await sendTransaction({ account: serverWallet, transaction: { chain: sepolia, client, to: targetAddress, value: 0n, }, }); console.log("Transaction successful:", tx.transactionHash); return tx; } catch (error) { console.error("Error executing transaction:", error); throw error; } } // Execute the function executeTransactionWithSessionKey() .then((tx) => console.log("Done!", tx.transactionHash)) .catch((error) => console.error("Failed:", error)); ``` -------------------------------- ### Create a new project with the thirdweb CLI Source: https://portal.thirdweb.com/tokens/build/get-started Command to create a new project using the thirdweb CLI. ```bash npx thirdweb create contract ``` -------------------------------- ### Install required peer dependencies for React Native SDK Source: https://portal.thirdweb.com/react-native/v5/getting-started Installs essential peer dependencies required by the thirdweb React Native SDK. ```bash npx expo install react-native-get-random-values @react-native-community/netinfo expo-application @react-native-async-storage/async-storage expo-web-browser expo-linking react-native-aes-gcm-crypto react-native-quick-crypto amazon-cognito-identity-js @coinbase/wallet-mobile-sdk react-native-mmkv react-native-svg @walletconnect/react-native-compat react-native-passkey ``` -------------------------------- ### Send Test Transaction (cURL) Source: https://portal.thirdweb.com/engine/v3/get-started Example cURL command to send a test transaction using the thirdweb Transactions API. ```curl curl -X POST "https://engine.thirdweb.com/v1/write/contract" \ -H "Content-Type: application/json" \ -H "x-secret-key: " \ -H "x-vault-access-token: " \ -d '{ "executionOptions": { "from": "", "chainId": "84532" }, "params": [ { "contractAddress": "0x...", "method": "function mintTo(address to, uint256 amount)", "params": ["0x...", "100"] } ] }' ``` -------------------------------- ### Quick start Source: https://portal.thirdweb.com/dotnet/wallets/server-wallet Instantiate a server wallet by providing the client and label. ```.cs var client = ThirdwebClient.Create(secretKey: Environment.GetEnvironmentVariable("THIRDWEB_SECRET_KEY")); var wallet = await ServerWallet.Create( client: client, label: "production-deployer" ); Console.WriteLine($"Server wallet ready at {await wallet.GetAddress()}."); ``` -------------------------------- ### Complete Workflow Example Source: https://portal.thirdweb.com/changelog Example demonstrating the complete workflow of signing and then broadcasting a Solana transaction using cURL and jq. ```bash # Step 1: Sign the transaction SIGNED_TX=$(curl -X POST https://api.thirdweb.com/v1/solana/sign-transaction \ -H "Content-Type: application/json" \ -H "x-secret-key: YOUR_SECRET_KEY" \ -d '{ "from": "8JBLmveV4YF5AQ7EVnKJgyj6etGgVkPp3tYqQMTu3p5B", "chainId": "solana:devnet", "instructions": [...] }' | jq -r '.result.signedTransaction') # Step 2: Broadcast the signed transaction curl -X POST https://api.thirdweb.com/v1/solana/broadcast-transaction \ -H "Content-Type: application/json" \ -H "x-secret-key: YOUR_SECRET_KEY" \ -d "{ \"chainId\": \"solana:devnet\", \"signedTransaction\": \"$SIGNED_TX\" }" ``` -------------------------------- ### Example of overriding the mintTo function Source: https://portal.thirdweb.com/tokens/build/get-started This example demonstrates how to override the `mintTo` function from `ERC721Base` to add custom logic, restricting minting to one NFT per wallet, and using `super` to call the original parent function. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@thirdweb-dev/contracts/base/ERC721Base.sol"; import "@thirdweb-dev/contracts/extension/Permissions.sol"; contract MyNFT is ERC721Base, Permissions { constructor( address _defaultAdmin, string memory _name, string memory _symbol, address _royaltyRecipient, uint128 _royaltyBps ) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {} function mintTo(address _to, string memory _tokenURI) public override { require(balanceOf(_to) < 1, "only 1 NFT per wallet!"); super.mintTo(_to, _tokenURI); } } ``` -------------------------------- ### Import thirdweb hooks, extensions, and wallets Source: https://portal.thirdweb.com/react-native/v5/getting-started Example of importing necessary components from the thirdweb package for use in a React Native application. ```javascript // import thirdweb hooks, extensions, provider and wallets as usual import { ThirdwebProvider } from "thirdweb/react"; import { balanceOf, claimTo } from "thirdweb/extensions/erc721"; import { inAppWallet } from "thirdweb/wallets/in-app"; ``` -------------------------------- ### createListing Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to create a direct listing. ```typescript import { createListing } from "thirdweb/extensions/marketplace"; import { sendTransaction } from "thirdweb"; const transaction = createListing({ assetContractAddress: "0x...", // the NFT contract address that you want to sell tokenId={0n}, // the token id you want to sell pricePerToken="0.1" // sell for 0.1 }); await sendTransaction({ transaction, account }); ``` -------------------------------- ### getOffer Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to retrieve an offer. ```typescript import { getOffer } from "thirdweb/extensions/marketplace"; const listing = await getOffer({ contract, listingId: 1n }); ``` -------------------------------- ### Overriding the _canMint function with Permissions extension Source: https://portal.thirdweb.com/tokens/build/get-started A Solidity smart contract example overriding the _canMint function to use the Permissions extension, allowing only those with MINTER_ROLE to mint. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@thirdweb-dev/contracts/base/ERC721Base.sol"; import "@thirdweb-dev/contracts/extension/Permissions.sol"; contract MyNFT is ERC721Base, Permissions { bytes32 private constant MINTER_ROLE = keccak256("MINTER_ROLE"); constructor( address _defaultAdmin, string memory _name, string memory _symbol, address _royaltyRecipient, uint128 _royaltyBps ) ERC721Base(_defaultAdmin, _name, _symbol, _royaltyRecipient, _royaltyBps) {} /** * `_canMint` is a function available in `ERC721Base`. * * It is called every time a wallet tries to mint NFTs on this * contract, and lets you define the condition in which an * attempt to mint NFTs should be permitted, or rejected. * * By default, `ERC721Base` only lets the contract's owner mint * NFTs. Here, we override that functionality. * * We use the `Permissions` extension to specify that anyone holding * "MINTER_ROLE" should be able to mint NFTs. */ function _canMint() internal view override returns (bool) { return hasRole(MINTER_ROLE, msg.sender); } } ``` -------------------------------- ### Run the Application Source: https://portal.thirdweb.com/contracts/arbitrum-stylus/zk-mint Navigate to the app directory and start the development server. ```bash cd app pnpm dev # Visit http://localhost:3000 ``` -------------------------------- ### ConnectButton with only In-App Wallets as Smart Accounts Source: https://portal.thirdweb.com/react/v5/account-abstraction/get-started This example configures the ConnectButton so that only in-app wallets are converted to smart accounts. External wallets will not be converted. ```typescript import { createThirdwebClient } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { ThirdwebProvider, ConnectButton } from "thirdweb/react"; import { inAppWallet, createWallet } from "thirdweb/wallets"; const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID", }); const wallets = [ inAppWallet({ // only configure smart accounts for in-app wallets smartAccount: { chain: sepolia, sponsorGas: true, }, }), // other external wallets will not become smart accounts createWallet("io.metamask"), createWallet("rainbow.me"), ]; export default function App() { return ( ); } ``` -------------------------------- ### Example Source: https://portal.thirdweb.com/llms-full.txt Deploy a regular contract from ABI and bytecode. ```typescript import { deployContract } from "thirdweb/deploys"; const address = await deployContract({ client, chain, bytecode: "0x...", abi: contractAbi, constructorParams: { param1: "value1", param2: 123, }, salt, // optional: salt enables deterministic deploys }); ``` -------------------------------- ### Get Rewards Example Source: https://portal.thirdweb.com/llms-full.txt An example of how to get rewards using the getRewards function. ```typescript import { getRewards } from "thirdweb/extensions/tokens"; const result = await getRewards({ contract, asset: ..., }); ``` ```typescript function getRewards(options: BaseTransactionOptions) : Promise> ``` -------------------------------- ### TransferableERC1155 Module Installation Example Source: https://portal.thirdweb.com/llms-full.txt Example of installing the TransferableERC1155 module on a core contract. ```typescript import { TransferableERC1155 } from "thirdweb/modules"; const transaction = TransferableERC1155.install({ contract: coreContract, account: account, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### EIP-5792 Get Capabilities Example Source: https://portal.thirdweb.com/llms-full.txt An example of how to get a wallet's capabilities using EIP-5792. ```typescript import { getCapabilities } from "thirdweb/wallets/eip5792"; const wallet = createWallet("com.coinbase.wallet"); const capabilities = await getCapabilities({ wallet }); ``` ```typescript function getCapabilities( options: GetCapabilitiesOptions, ): Promise<{ message?: string }>; ``` -------------------------------- ### Example prompt: Create a server wallet Source: https://portal.thirdweb.com/ai/mcp An example prompt for creating a server wallet. ```shell Create a server wallet called treasury ``` -------------------------------- ### ConnectButton with Account Abstraction Source: https://portal.thirdweb.com/react/v5/account-abstraction/get-started This example shows how to use the ConnectButton component with the `accountAbstraction` property to automatically convert connected wallets to smart accounts. It also demonstrates how to enable sponsored transactions. ```typescript import { createThirdwebClient } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { ThirdwebProvider, ConnectButton } from "thirdweb/react"; const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID", }); export default function App() { return ( ); } ``` -------------------------------- ### Get RPC URL For Chain Example Source: https://portal.thirdweb.com/llms-full.txt Example demonstrating how to get an RPC URL for a chain, with an option for a custom RPC. ```typescript import { getRpcUrlForChain } from "thirdweb/chains"; const rpcUrl = getRpcUrlForChain({ chain: 1, client }); console.log(rpcUrl); // "https://1.rpc.thirdweb.com/... ``` -------------------------------- ### WebGL Local Server Setup Source: https://portal.thirdweb.com/unity/v6/build-instructions Example setup for testing In-App or Ecosystem Wallet Social Login locally using Node.js and Express to set the 'Cross-Origin-Opener-Policy' header. ```javascript // YourWebGLOutputFolder/server.js const express = require("express"); const app = express(); const port = 8000; app.use((req, res, next) => { res.header( "Cross-Origin-Opener-Policy", "same-origin-allow-popups", ); next(); }); app.use(express.static(".")); app.listen(port, () => console.log(`Server running on http://localhost:${port}`), ); // run it with `node server.js` ``` -------------------------------- ### EIP-5792 Get Calls Status Example Source: https://portal.thirdweb.com/llms-full.txt An example demonstrating how to send calls and then get their status using EIP-5792 functions. ```typescript import { createThirdwebClient } from "thirdweb"; import { sendCalls, getCallsStatus } from "thirdweb/wallets/eip5792"; const client = createThirdwebClient({ clientId: ... }); const result = await sendCalls({ wallet, client, calls }); let result; while (result.status !== "success") { result = await getCallsStatus(result); } ``` ```typescript function getCallsStatus( options: GetCallsStatusOptions, ): Promise<{ atomic: boolean; chainId: number; id: string; receipts?: Array>; status: undefined | "pending" | "success" | "failure"; statusCode: number; version: string; }>; ``` -------------------------------- ### prepareUserOp Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to prepare a user operation for signing. ```typescript import { prepareUserOp } from "thirdweb/wallets/smart"; const userOp = await prepareUserOp({ transactions, adminAccount, client, smartWalletOptions, }); ``` -------------------------------- ### Custom UI with useConnect hook Source: https://portal.thirdweb.com/react/v5/account-abstraction/get-started This example demonstrates how to use the `useConnect` hook to connect to smart accounts and build a custom UI. It shows how to configure `accountAbstraction` for the hook and initiate the connection process. ```typescript import { useConnect } from "thirdweb/react"; import { inAppWallet } from "thirdweb/wallets"; import { sepolia } from "thirdweb/chains"; function App() { // 1. set the `accountAbstraction` configuration to convert wallets to smart accounts const { connect } = useConnect({ client, accountAbstraction: { chain: sepolia, // the chain where your smart accounts will be or is deployed sponsorGas: true, // enable or disable sponsored transactions }, }); const connectToSmartAccount = async () => { // 2. connect with the admin wallet of the smart account connect(async () => { const wallet = inAppWallet(); // or any other wallet await wallet.connect({ client, chain: sepolia, strategy: "google", }); return wallet; }); }; return ( ); } ``` -------------------------------- ### Get CHANGE_RECOVERY_ADDRESS_TYPEHASH Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the `CHANGE_RECOVERY_ADDRESS_TYPEHASH`. ```typescript import { CHANGE_RECOVERY_ADDRESS_TYPEHASH } from "thirdweb/extensions/farcaster"; const result = await CHANGE_RECOVERY_ADDRESS_TYPEHASH({ contract, }); ``` ```typescript function CHANGE_RECOVERY_ADDRESS_TYPEHASH( options: BaseTransactionOptions, ): Promise<`0x${string}`>; ``` -------------------------------- ### Example Source: https://portal.thirdweb.com/llms-full.txt Example of getting contract events. ```typescript import { Insight } from "thirdweb"; const events = await Insight.getContractEvents({ client, chains: [sepolia], contractAddress: "0x1234567890123456789012345678901234567890", event: transferEvent(), decodeLogs: true, }); ``` -------------------------------- ### Send a Transaction Source: https://portal.thirdweb.com/wallets/quickstart Prepare and send a transaction using extensions, getContract, and useSendTransaction. ```typescript import { getContract } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { useSendTransaction } from "thirdweb/react"; // 1. import the extension you want to use import { transfer } from "thirdweb/extensions/erc20"; // 2. define the target contract const USDC = getContract({ client, address: USDC_ADDRESS, chain: sepolia, }); export default function MyComponent() { // 3. call the useSendTransaction hook const { mutate: sendTransaction, isPending } = useSendTransaction(); const onClick = () => { // 4. execute the transaction (send 15 USDC to the target address) const transaction = transfer({ contract: USDC, amount: 15, to: "0x...", }); sendTransaction(transaction); }; } ``` -------------------------------- ### Setup Core Contract Source: https://portal.thirdweb.com/tokens/modular-contracts/get-started/create-core-contract This snippet shows the basic structure for setting up a core contract, including the `supportsInterface` function. ```solidity ) public view override returns (bool) { return interfaceId == 0x00000001 || super.supportsInterface(interfaceId); } } ``` -------------------------------- ### Example Usage Source: https://portal.thirdweb.com/typescript/v5/getBuyWithFiatStatus This example shows how to get the status of a buy with fiat transaction. ```typescript // step 1 - get a quote const fiatQuote = await getBuyWithFiatQuote(fiatQuoteParams); // step 2 - open the on-ramp provider UI window.open(quote.onRampLink, "_blank"); // step 3 - keep calling getBuyWithFiatStatus while the status is in one of the pending states const fiatStatus = await getBuyWithFiatStatus({ client, intentId: fiatQuote.intentId, }); // when the fiatStatus.status is "ON_RAMP_TRANSFER_COMPLETED" - the process is complete ``` -------------------------------- ### Usage with options Source: https://portal.thirdweb.com/cli/build Shows the general usage of the thirdweb CLI with available options. ```bash npx thirdweb [options] ``` -------------------------------- ### Setup the ThirdwebProvider Source: https://portal.thirdweb.com/react/v5/in-app-wallet/build-your-own-ui This will ensure that the wallet is available to all components in your app, handle connection states and auto-connection on page load. ```javascript import { ThirdwebProvider } from "thirdweb/react"; ; ``` -------------------------------- ### getBuyWithCryptoStatus Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the status of a buy with crypto transaction. It includes steps for getting a quote, handling approvals, sending the transaction, and polling for status. ```typescript import { sendTransaction } from "thirdweb"; import { getBuyWithCryptoStatus, getBuyWithCryptoQuote } from "thirdweb/pay"; // get a quote between two tokens const quote = await getBuyWithCryptoQuote(quoteParams); // if approval is required, send the approval transaction if (quote.approval) { const txResult = await sendTransaction({ transaction: quote.approval, account: account, // account from connected wallet }); await waitForReceipt(txResult); } // send the quoted transaction const swapTxResult = await sendTransaction({ transaction: quote.transactionRequest, account: account, // account from connected wallet }); await waitForReceipt(swapTxResult); // keep polling the status of the quoted transaction until it returns a success or failure status const status = await getBuyWithCryptoStatus({ client, transactionHash: swapTxResult.transactionHash, }); ``` -------------------------------- ### Example prompt: List server wallets Source: https://portal.thirdweb.com/ai/mcp An example prompt for listing server wallets. ```shell List my server wallets ``` -------------------------------- ### Install ClaimableERC721 Module Source: https://portal.thirdweb.com/llms-full.txt Example of installing the ClaimableERC721 module. ```typescript import { ClaimableERC721 } from "thirdweb/modules"; const transaction = ClaimableERC721.install({ contract: coreContract, account: account, params: { primarySaleRecipient: ..., }, }); await sendTransaction({ transaction, account, }); ``` ```typescript function install(options: { account: Account; contract: Readonly; params: EncodeBytesOnInstallParams & { publisher?: string }; }): PreparedTransaction; ``` ```typescript let options: { account: Account; contract: Readonly; params: EncodeBytesOnInstallParams & { publisher?: string }; }; ``` ```typescript let returnType: Readonly & { __contract?: ThirdwebContract; __preparedMethod?: () => Promise>; }; ``` -------------------------------- ### ClaimableERC20.install Example Source: https://portal.thirdweb.com/llms-full.txt Installs the ClaimableERC20 module on a core contract. ```typescript import { ClaimableERC20 } from "thirdweb/modules"; const transaction = ClaimableERC20.install({ contract: coreContract, account: account, params: { primarySaleRecipient: ..., }, }); await sendTransaction({ transaction, account, }); ``` -------------------------------- ### getUserOpReceipt Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the receipt of a user operation. ```typescript import { getUserOpReceipt } from "thirdweb/wallets/smart"; const receipt = await getUserOpReceipt({ client, chain, userOpHash, }); ``` -------------------------------- ### Step 2: Get Account Contract Source: https://portal.thirdweb.com/wallets/session-keys Create a contract instance for the deployed smart EOA: ```typescript const accountContract = getContract({ address: account.address, chain: sepolia, client: client, }); ``` -------------------------------- ### createWallet Example (MetaMask) Source: https://portal.thirdweb.com/llms-full.txt Example of creating and connecting to the MetaMask wallet. ```typescript import { createWallet } from "thirdweb/wallets"; const metamaskWallet = createWallet("io.metamask"); const account = await metamaskWallet.connect({ client, }); ``` -------------------------------- ### getUserOpHash Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the hash of a user operation. ```typescript import { getUserOpHash } from "thirdweb/wallets/smart"; const userOp = await createUnsignedUserOp (...); const userOpHash = await getUserOpHash({ client, userOp, chain, }); ``` -------------------------------- ### Create Wallet Example Source: https://portal.thirdweb.com/wallets/solana Example of creating a new Solana wallet using the thirdweb API. ```bash curl -X POST "https://api.thirdweb.com/v1/solana/wallets" \ -H "Content-Type: application/json" \ -H "x-secret-key: YOUR_SECRET_KEY" \ -d '{"label": "treasury-wallet"}' ``` -------------------------------- ### getProposalVoteCounts Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get vote counts for a proposal. ```typescript import { getProposalVoteCounts } from "thirdweb/extensions/vote"; const data = await getProposalVoteCounts({ contract, proposalId }); // Example result { for: 12000000000000000000n, // 12 tokens (with a decimals of 18) were used to vote "for" against: 7000000000000000000n, // 7 tokens (with a decimals of 18) were used to vote "against" abstain: 0n, // no user has voted abstain on this proposal } ``` ```typescript function getProposalVoteCounts( options: BaseTransactionOptions ): Promise; ``` -------------------------------- ### Initialize Thirdweb Client Source: https://portal.thirdweb.com/dotnet/getting-started Creates a new instance of the Thirdweb client for different application types. ```csharp // For Web Applications var client = ThirdwebClient.Create(clientId: "yourClientId"); // For Native Applications var client = ThirdwebClient.Create(clientId: "yourClientId", bundleId: "yourBundleId"); // For Backend Applications var client = ThirdwebClient.Create(secretKey: "yourSecretKey"); ``` -------------------------------- ### Example Source: https://portal.thirdweb.com/llms-full.txt Deploy a contract deterministically. ```typescript import { deployContract } from "thirdweb/deploys"; const address = await deployContract({ client, chain, bytecode: "0x...", abi: contractAbi, constructorParams: { param1: "value1", param2: 123, }, salt, // passing a salt will enable deterministic deploys }); ``` -------------------------------- ### Create Account Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to prepare a transaction to call the createAccount function. ```typescript import { sendTransaction } from "thirdweb"; import { createAccount } from "thirdweb/extensions/erc4337"; const transaction = createAccount({ contract, admin: ..., data: ..., overrides: { ... } }); // Send the transaction await sendTransaction({ transaction, account }); ``` ```typescript function createAccount( options: BaseTransactionOptions< | CreateAccountParams | { asyncParams: () => Promise } >, ): PreparedTransaction; ``` -------------------------------- ### Create a new project Source: https://portal.thirdweb.com/cli/create Run this command to start creating a new project. ```bash npx thirdweb create ``` -------------------------------- ### Get a contract Source: https://portal.thirdweb.com/typescript/v5/contract Example of how to get a contract instance using the thirdweb SDK. ```typescript import { getContract } from "thirdweb"; import { ethereum } from "thirdweb/chains"; // get a contract const contract = getContract({ // the client you have created via `createThirdwebClient()` client, // the chain the contract is deployed on chain: ethereum, // the contract's address address: "0x123...", // OPTIONAL: the contract's abi abi: [...], }); ``` -------------------------------- ### Get Balance Source: https://portal.thirdweb.com/dotnet/wallets/actions/getbalance Example usage for getting the native token balance or an ERC20 token balance. ```csharp // Get native balance BigInteger nativeBalance = await wallet.GetBalance(chainId); // Get ERC20 token balance BigInteger tokenBalance = await wallet.GetBalance(chainId, erc20ContractAddress); ``` -------------------------------- ### Example Source: https://portal.thirdweb.com/llms-full.txt Basic usage example of ThirdwebProvider. ```jsx import { ThirdwebProvider } from "thirdweb/react"; function Example() { return ( ); } ``` -------------------------------- ### RainbowKit Initialization Source: https://portal.thirdweb.com/react/v5/rainbow-kit-migrate Example of initializing RainbowKit. ```typescript import "@rainbow-me/rainbowkit/styles.css"; import { getDefaultConfig, RainbowKitProvider, } from "@rainbow-me/rainbowkit"; import { WagmiProvider } from "wagmi"; import { mainnet, polygon, optimism, arbitrum, base, } from "wagmi/chains"; import { QueryClientProvider, QueryClient, } from "@tanstack/react-query"; const config = getDefaultConfig({ appName: "My RainbowKit App", projectId: "YOUR_PROJECT_ID", chains: [mainnet, polygon, optimism, arbitrum, base], ssr: true, // If your dApp uses server side rendering (SSR) }); const queryClient = new QueryClient(); const App = () => { return ( {/* Your App */} ); }; ``` -------------------------------- ### getUserOpReceiptRaw Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the raw receipt of a user operation. ```typescript import { getUserOpReceiptRaw } from "thirdweb/wallets/smart"; const receipt = await getUserOpReceiptRaw({ client, chain, userOpHash, }); ``` -------------------------------- ### privateKeyToAccount Example Source: https://portal.thirdweb.com/llms-full.txt Example of getting an Account object from a private key. ```typescript import { privateKeyToAccount } from "thirdweb/wallets"; const wallet = privateKeyToAccount({ client, privateKey: "...", }); ``` -------------------------------- ### Fetch Source: https://portal.thirdweb.com/connect/wallet/overview Initiate social OAuth authentication. ```javascript fetch("https://api.thirdweb.com/v1/auth/social", { method: "GET", headers: { "x-client-id": "", }, }); ``` -------------------------------- ### Setup Imports and Configuration Source: https://portal.thirdweb.com/engine/v3/guides/session-keys Imports necessary functions from the thirdweb SDK and configures the client, session key address, and target address. ```typescript import { generateAccount, smartWallet, sendTransaction, getContract, createThirdwebClient, } from "thirdweb"; import { sepolia } from "thirdweb/chains"; import { getAllActiveSigners } from "thirdweb/extensions/erc4337"; import { Engine } from "thirdweb/engine"; // Configure your client const client = createThirdwebClient({ clientId: "your-client-id", secretKey: "your-secret-key", // Only use in server environments }); // Your session key account address const sessionKeyAccountAddress = "0x..."; // Replace with your session key address // Target address for transactions const targetAddress = "0x..."; // Replace with your target address ``` -------------------------------- ### SetIdGatewayEvent Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the SetIdGateway event from the Farcaster contract. ```typescript import { getContractEvents } from "thirdweb"; import { setIdGatewayEvent } from "thirdweb/extensions/farcaster"; const events = await getContractEvents({ contract, events: [setIdGatewayEvent()], }); ``` ```typescript function setIdGatewayEvent(): PreparedEvent<{ readonly inputs: readonly [ { readonly name: "oldIdGateway"; readonly type: "address" }, { readonly name: "newIdGateway"; readonly type: "address" }, ]; readonly name: "SetIdGateway"; readonly type: "event"; }>; ``` -------------------------------- ### SetIdCounterEvent Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get the SetIdCounter event from the Farcaster contract. ```typescript import { getContractEvents } from "thirdweb"; import { setIdCounterEvent } from "thirdweb/extensions/farcaster"; const events = await getContractEvents({ contract, events: [setIdCounterEvent()], }); ``` ```typescript function setIdCounterEvent(): PreparedEvent<{ readonly inputs: readonly [ { readonly name: "oldCounter"; readonly type: "uint256" }, { readonly name: "newCounter"; readonly type: "uint256" }, ]; readonly name: "SetIdCounter"; readonly type: "event"; }>; ``` -------------------------------- ### createWalletAdapter Example Source: https://portal.thirdweb.com/llms-full.txt Example of creating a wallet adapter to convert third-party wallets or connect with private keys. ```typescript import { createWalletAdapter } from "thirdweb"; const wallet = createWalletAdapter({ client, adaptedAccount, chain, onDisconnect: () => { // disconnect logic }, switchChain: async (chain) => { // switch chain logic }, }); ``` ```typescript function createWalletAdapter( options: AdapterWalletOptions, ): Wallet<"adapter">; ``` -------------------------------- ### SharedMetadataUpdated Event Example Source: https://portal.thirdweb.com/llms-full.txt Example of how to get SharedMetadataUpdated events from a contract. ```typescript import { getContractEvents } from "thirdweb"; import { sharedMetadataUpdatedEvent } from "thirdweb/extensions/erc721"; const events = await getContractEvents({ contract, events: [sharedMetadataUpdatedEvent()] }); ``` ```typescript function sharedMetadataUpdatedEvent(): PreparedEvent<{ readonly inputs: readonly [ { readonly name: "name"; readonly type: "string" }, { readonly name: "description"; readonly type: "string" }, { readonly name: "imageURI"; readonly type: "string" }, { readonly name: "animationURI"; readonly type: "string" }, ]; readonly name: "SharedMetadataUpdated"; readonly type: "event"; }>; ``` -------------------------------- ### Example Usage Source: https://portal.thirdweb.com/llms-full.txt Example of how to use the getFullProfile function. ```typescript import { getFullProfile } from "thirdweb/extension/lens"; const profileId = 10000n; // profileId is the tokenId of the NFT const lensProfile = await getFullProfile({ profileId, client }); ``` -------------------------------- ### Example prompt: Get wallet balance Source: https://portal.thirdweb.com/ai/mcp An example prompt for checking a wallet's balance. ```shell What's the balance of treasury wallet? ``` -------------------------------- ### Install BatchMetadataERC1155 Module Source: https://portal.thirdweb.com/llms-full.txt Example of installing the BatchMetadataERC1155 module on a core contract. ```typescript import { BatchMetadataERC1155 } from "thirdweb/modules"; const transaction = BatchMetadataERC1155.install({ contract: coreContract, account: account, }); await sendTransaction({ transaction, account, }); ``` ```typescript function install(options: { account: Account; contract: Readonly; params?: { publisher?: string }; }): PreparedTransaction; ```