1

I want to create wallet account via Rust program by using payer & mint account, in that case how to predict the number of bytes to allocate for the new account data so that I can pay less rent ?

let space = spl_token::state::Account::get_packed_len(); //Number of bytes to allocate for the new account data    
let rent = rpc.get_minimum_balance_for_rent_exemption(space)?; //Calculate min rent according to expected account data size

//Build instruction for create account 
let create_token_acc_ix = solana_program::system_instruction::create_account(
    &payer_pubkey,
    &wallet_pubkey,
    rent,
    space as u64,
    &spl_token::ID,
);

2 Answers 2

1

you can find space for each type HERE.

0

use spl_token::state::Mint; let space = Mint::LEN;

spl_token::state::Account::get_packed_len() gives you the wrong size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.