thirdweb SDK
Introduction
thirdweb is a complete web3 development framework that provides everything you need to connect your apps and games to decentralized networks
Prerequisites
- Latest version of Node.js installed.
- Astar network wallet set up with basic usage knowledge.
- Basic knowledge of React.
Getting started
Creating an app
thirdweb provides several SDKs to allow you to interact with your contract including: React, React Native, TypeScript, Python, Go, and Unity.
This document will show you how to interact with your contract deployed to Astar using React
View the full React SDK reference in thirdweb’s documentation.
To create a new application pre-configured with thirdweb’s SDKs run and choose your preferred configurations:
npx thirdweb create app --evm
or install it into your existing project by running:
npx thirdweb install
Initialize SDK on Astar
Wrap your application in the ThirdwebProvider
component and change the activeChain
to Astar
import { ThirdwebProvider } from "@thirdweb-dev/react";
import { Astar } from "@thirdweb-dev/chains";
const App = () => {
return (
<ThirdwebProvider activeChain={Astar}>
<YourApp />
</ThirdwebProvider>
);
};
Get contract
To connect to your contract, use the SDK’s getContract
method.
import { useContract } from "@thirdweb-dev/react";
function App() {
const { contract, isLoading, error } = useContract("{{contract_address}}");
}
Calling contract functions
-
For extension based functions, use the built-in supported hooks. The following is an example using the NFTs extension to access a list of NFTs owned by an address-
useOwnedNFTs
import { useOwnedNFTs, useContract, useAddress } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const address = useAddress();
const { contract } = useContract(contractAddress);
const { data, isLoading, error } = useOwnedNFTs(contract, address);
}