Programs
You can get an SDK instance for any program by providing the address of the program as follows:
- React
- Javascript
import { useProgram } from "@thirdweb-dev/react/solana"
export default function Component() {
const { program } = useProgram("{{program_address}}")
...
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
const sdk = ThirdwebSDK.fromNetwork("devnet");
sdk.wallet.connect(signer);
// Get the interface for your program
const program = await sdk.getProgram("{{program_address}}");
Calling Functions
You can call any function on your program including functions to read data or write a transaction to the blockchain by providing:
- The name of the function you want to call
- The parameters to pass to the function
- React
- Javascript
const counterAccount = Keypair.generate();
await program.call("increment", {
// We need to pass in the public keys of any accounts to interact with
accounts: {
counterAccount: counterAccount.publicKey.toBase58(),
},
// As well as the arguments to pass to the data parameters
data: ["..."],
// And the signer of the account that will be signing the message
signers: [counterAccount]
})
const counterAccount = Keypair.generate();
await program.call("increment", {
// We need to pass in the public keys of any accounts to interact with
accounts: {
counterAccount: counterAccount.publicKey.toBase58(),
},
// As well as the arguments to pass to the data parameters
data: ["..."],
// And the signer of the account that will be signing the message
signers: [counterAccount]
})
Reading Account Data
You can also read the data from any account associated with your program by using the program.fetch
function as follows:
- React
- Javascript
const accountAddress = "...";
// Get the counterAccount at specified address
const counterAccount = await program.fetch("counterAccount", accountaddress);
const accountAddress = "...";
// Get the counterAccount at specified address
const counterAccount = await program.fetch("counterAccount", accountaddress);