
Security News
Static vs. Runtime Reachability: Insights from Latio’s On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
@thirdweb-dev/react-core
Advanced tools
Ultimate collection of React hooks for your web3 apps
You can install the SDK into your existing project using npm or yarn:
npm install @thirdweb-dev/react-core @thirdweb-dev/sdk ethers
yarn add @thirdweb-dev/react-core @thirdweb-dev/sdk ethers
Our SDK uses a Provider Pattern; meaning any component within the ThirdwebSDKProvider
will have access to the SDK.
Let's take a look at a typical setup:
ThirdwebSDKProvider
Specify the network your smart contracts are deployed to in the desiredChainId
prop and wrap your application like so:
import { ChainId, ThirdwebSDKProvider } from "@thirdweb-dev/react-core";
const App = () => {
return (
<ThirdwebSDKProvider desiredChainId={ChainId.Mainnet} provider={yourWeb3ProviderOrSigner}>
<YourApp />
</ThirdwebProvider>
);
};
Note that you will need to provide an ethers provider or signer for you application. If you want further abstraction please
see our react
and react-native
SDKs which have their own providers.
Below are examples of where to set this up in your application:
Create React App • Next.js • Vite
Connect to your smart contract using the useContract
hook like so:
import { useContract } from "@thirdweb-dev/react-core";
export default function Home() {
const { contract } = useContract("<CONTRACT_ADDRESS>");
// Now you can use the contract in the rest of the component!
}
You can then use useContractRead
and useContractWrite
to read data and write transactions to the contract.
You pass the contract
object returned from useContract
to these hooks as the first parameter and the name of the function (or view/mapping, etc.) on your smart contract as the second parameter. If your function requires parameters, you can pass them as additional arguments.
For example, we can read the name
of our contract like so:
import {
useContract,
useContractRead,
useContractWrite,
} from "@thirdweb-dev/react-core";
export default function Home() {
const { contract } = useContract("<CONTRACT_ADDRESS>");
const { data: name, isLoading: loadingName } = useContractRead(
contract,
"name", // The name of the view/mapping/variable on your contract
);
const { mutate: setName, isLoading: settingName } = useContractWrite(
contract,
"setName", // The name of the function on your contract
);
}
Each extension you implement in your smart contract unlocks new functionality in the SDK.
These hooks make it easy to interact with your smart contracts by implementing the complex logic for you under the hood.
For example, if your smart contract implements ERC721Supply, you unlock the ability to view all NFTs on that contract using the SDK; which fetches all of your NFT metadata and the current owner of each NFT in parallel. In the React SDK, that is available using useNFTs
:
import { useContract, useNFTs } from "@thirdweb-dev/react-core";
export default function Home() {
const { contract } = useContract("<CONTRACT_ADDRESS>");
const { data: nfts, isLoading: isReadingNfts } = useNFTs(contract);
}
If we want to mint an NFT and our contract implements ERC721Mintable, we can use the useMintNFT
hook to mint an NFT from the connected wallet; handling all of the logic of uploading and pinning the metadata to IPFS for us behind the scenes.
import { useContract, useNFTs, useMintNFT } from "@thirdweb-dev/react-core";
export default function Home() {
const { contract } = useContract("<CONTRACT_ADDRESS>");
const { data: nfts, isLoading: isReadingNfts } = useNFTs(contract);
const { mutate: mintNFT, isLoading: isMintingNFT } = useMintNFT(contract);
}
FAQs
thirdweb React Core SDK
The npm package @thirdweb-dev/react-core receives a total of 1,879 weekly downloads. As such, @thirdweb-dev/react-core popularity was classified as popular.
We found that @thirdweb-dev/react-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.