Getting started
From your project folder:
Note If you are using a
solana-program
version prior to1.16
, first add thesolana-program
dependency to your project and then addmpl-bubblegum
. This will make sure you only have a single copy of theborsh
crate.
Structure
The client SDK is divided into several modules:
accounts
: structs representing the accounts of the programerrors
: enums representing the program errorsinstructions
: structs to facilitate the creation of instructions, instruction arguments and CPI instructionstypes
: structs representing types used by the program
Instruction Builders
One of the main features of the client SDK is to facilitate the creation of instructions. There are two "types" of instruction builders automatically generated – both support passing accounts by name and optional positional.
Client instruction builders
This are intended to be used by off-chain client code. Each instruction is represented by a corresponding struct – e.g., MintV1
:
After filling in the instruction account fields, you can use the instruction(...)
method to generate the corresponding solana_program::instruction::Instruction
:
// instruction args
let metadata = MetadataArgs ;
// instruction accounts
let mint_ix = MintV1 ;
// creates the instruction
let create_ix = create_ix.instruction;
Alternatively, you can use the MintV1Builder
to create the appropriate instruction:
let mint_ix = new
.tree_config
.leaf_owner
.leaf_delegate
.merkle_tree
.payer
.tree_creator_or_delegate
.metadata
.instruction;
CPI instruction builders
These are builders to be used by on-chain code, which will CPI into Bubblegum. Similarly to "off-chain" builders, each instruction has a struct to invoke CPI instructions – e.g., MintV1Cpi
:
After filling in the program, instruction accounts and argument fields, you can use the invoke()
or invoke_signed(...)
method to perform the CPI:
// instruction args
let metadata = MetadataArgs ;
// instruction accounts
let cpi_mint = new;
// performs the CPI
cpi_mint.invoke_signed
You can also use the MintV1CpiBuilder
to simplify the process:
let cpi_mint = new
.compression_program
.leaf_delegate
.leaf_owner
.log_wrapper
.merkle_tree
.payer
.system_program
.tree_config
.metadata;
// performs the CPI
cpi_mint.invoke_signed
Note >
*Builder
provide a simplified way to create the required structs, since they take advantage of any default value set on the Kinobi config and do not require to set aNone
value to optional fields.
PDA helpers
Account types (e.g., TreeConfig
) have associated functions to find PDA or to create PDA TreeConfig
s:
If a bump seed is known, it is cheaper (in terms of compute units) to use the
create_pda
function, in particular for on-chain code.
Testing
To run the SDK tests, run the following from the root directory of the repository:
and then:
Documentation
The crate documentation can be found here.