Skip to main content

Programs

You can get an SDK instance for any program by providing the address of the program as follows:

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:

  1. The name of the function you want to call
  2. The parameters to pass to the function
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]
})
View in Javascript SDK Documentation

Reading Account Data

You can also read the data from any account associated with your program by using the program.fetch function as follows:

const accountAddress = "...";
// Get the counterAccount at specified address
const counterAccount = await program.fetch("counterAccount", accountaddress);
View in Javascript SDK Documentation