-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_token_account.rs
More file actions
34 lines (28 loc) · 1018 Bytes
/
create_token_account.rs
File metadata and controls
34 lines (28 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use light_client::rpc::Rpc;
use light_token::instruction::CreateTokenAccount;
use rust_client::{setup_spl_mint_context, SplMintContext};
use solana_sdk::{signature::Keypair, signer::Signer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup creates mint
// You can use Light, SPL, or Token-2022 mints to create a light token account.
let SplMintContext {
mut rpc,
payer,
mint,
} = setup_spl_mint_context().await;
let account = Keypair::new();
let create_token_account_instruction =
CreateTokenAccount::new(payer.pubkey(), account.pubkey(), mint, payer.pubkey())
.instruction()?;
let sig = rpc
.create_and_send_transaction(&[create_token_account_instruction], &payer.pubkey(), &[&payer, &account])
.await?;
let data = rpc.get_account(account.pubkey()).await?;
println!(
"Account: {} exists: {} Tx: {sig}",
account.pubkey(),
data.is_some()
);
Ok(())
}