Tokens
Connect to your Token program by providing the on-chain address of the program:
- React
- Javascript
import { useProgram } from "@thirdweb-dev/react/solana"
export default function Component() {
const { program } = useProgram("{{program_address}}", "token")
...
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
const sdk = ThirdwebSDK.fromNetwork("devnet");
sdk.wallet.connect(signer);
// Get the interface for your token program
const program = await sdk.getProgram("{{program_address}}", "token");
Get Token Metadata
- React
- Javascript
const metadata = await program.getMetadata();
console.log(metadata.supply);
console.log(metadata.decimals);
const metadata = await program.getMetadata();
console.log(metadata.supply);
console.log(metadata.decimals);
Get Token Balance
- React
- Javascript
const address = "..."
const balance = await program.balanceOf(address);
console.log(balance.displayValue);
const address = "..."
const balance = await program.balanceOf(address);
console.log(balance.displayValue);
Mint Tokens
- React
- Javascript
// Specify the address to mint tokens to
const address = "{{wallet_address}}"";
// And the amount of tokens to mint
const amount = 1;
// And then you can make a mint transaction
const tx = await program.mintTo(address, 1);
// Specify the address to mint tokens to
const address = "{{wallet_address}}"";
// And the amount of tokens to mint
const amount = 1;
// And then you can make a mint transaction
const tx = await program.mintTo(address, 1);
Transfer Tokens
- React
- Javascript
// Specify the address to transfer tokens to
const to = "...";
// And the amount of tokens to transfer
const amount = 1;
// And then you can make the transfer transaction
const tx = await program.transfer(to, amount);
// Specify the address to transfer tokens to
const to = "...";
// And the amount of tokens to transfer
const amount = 1;
// And then you can make the transfer transaction
const tx = await program.transfer(to, amount);