thirdweb SDK is a library that enables developers to build web3 applications and interact with any EVM-compatible blockchain.
You can use the thirdweb SDK to build apps and interact with smart contracts deployed on the Pivotal network.
The thirdweb SDK is available in various programming languages, including: React, React Native, TypeScript, Python, Go, and Unity.
Visit the thirdweb documentation for more instructions on using the thirdweb SDKs.
To install the thirdweb SDK, run:
To get started using the SDK, you must first initialize an instance of ThirdWebSDK
, and connect to the Pivotal network by passing in the Pivotal
chain.
To initialize the SDK with the Pivotal network and get a contract:
The code snippet above uses the React SDK. The thirdweb SDKs are also available in React Native, TypeScript, Python, Go, and Unity.
If alternatively you'd like to initialize the SDK with Pivotal Sepolia (testnet), use the following code instead:
Once you initialize the SDK and connect to a smart contract deployed to Pivotal, you can start calling functions on it using the SDK.
Any interaction you make with a smart contract will be made from the connected wallet automatically.
The thirdweb SDK provides convenience functions when your smart contract uses extensions. This is the easiest way to read data and write transactions with your smart contracts.
For example, if your contract implements the ERC721 extension, you can utilize all of the functions of the corresponding erc721 standard in the SDK.
As an example, below is a code snippet that uses useOwnedNFTs
hook to get a list of NFTs owned by a single wallet address:
Usage
For more examples on using contract extension functions, visit the thirdweb developer documentation.
If your contract doesn’t use any extensions, or you want to directly call functions on your smart contract to read data, you can use the useContractRead
hook.
Read data on your contract from a connected wallet:
If your contract doesn’t use any extensions, or you want to directly call functions on your smart contract to write data, you can use the useContractWrite
hook.
Make transactions on your contract from a connected wallet:
ethers.js is a JavaScript library that allows developers to interact with EVM-compatible blockchain networks.
You can use ethers.js to interact with smart contracts deployed on the Pivotal network.
To install ethers.js run the following command:
Before you can start using ethers.js, you need to import it into your project.
Add the following line of code to the top of your file to import ethers.js:
You can connect to Pivotal by instantiating a new ethers.js JsonRpcProvider
object with a RPC URL of the Pivotal network:
To alternatively connect to Pivotal Sepolia (testnet), change the above URL from https://mainnet.thepivotal.xyz
to https://sepolia.thepivotal.xyz
.
Once you have created a provider, you can use it to read data from the Pivotal network.
For example, you can use the getBlockNumber
method to get the latest block:
In order to write data to the Pivotal network, you need to create a Signer
.
You can create a Signer
by instantiating a new ethers.js Wallet
object, providing it with a private key and Provider
.
PRIVATE_KEY
is the private key of the wallet to use when creating the signer.
You can use ethers.js to interact with a smart contract on Pivotal by instantiating a Contract
object using the ABI and address of a deployed contract:
For write-only contracts, provide a Signer
object instead of a Provider
object:
CONTRACT_ADDRESS
is the address of the deployed contract.
Once you have created a Contract
object, you can use it to call desired methods on the smart contract:
web3.js is a JavaScript library that allows developers to interact with EVM-compatible blockchain networks.
You can use web3.js to interact with smart contracts deployed on the Base network.
To install web3.js run the following command:
Before you can start using web3.js, you need to import it into your project.
Add the following line of code to the top of your file to import web3.js:
You can connect to Pivotal by instantiating a new web3.js Web3
object with a RPC URL of the Base network:
To alternatively connect to Pivotal Sepolia (testnet), change the above URL from https://mainnet.thepivotal.xyz
to https://sepolia.thepivotal.xyz
.
Once you have created a provider, you can use it to read data from the Pivotal network.
For example, you can use the getBlockNumber
method to get the latest block:
Before you can deploy a contract to the Pivotal network using web3.js, you must first create an account.
You can create an account by using web3.eth.accounts
:
PRIVATE_KEY
is the private key of the wallet to use when creating the account.
You can use web3.js to interact with a smart contract on Pivotal by instantiating a Contract
object using the ABI and address of a deployed contract:
Once you have created a Contract
object, you can use it to call desired methods on the smart contract:
For more information on deploying contracts on Pivotal, see Deploying a Smart Contract.