-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmint_to.rs
More file actions
44 lines (38 loc) · 1.24 KB
/
mint_to.rs
File metadata and controls
44 lines (38 loc) · 1.24 KB
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
35
36
37
38
39
40
41
42
43
44
use borsh::BorshDeserialize;
use light_client::rpc::Rpc;
use light_token_client::actions::{CreateAta, CreateMint, MintTo};
use rust_client::setup_rpc_and_payer;
use solana_sdk::signer::Signer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (mut rpc, payer) = setup_rpc_and_payer().await;
// Create mint (payer is also mint authority)
let (_signature, mint) = CreateMint {
decimals: 9,
freeze_authority: None,
token_metadata: None,
seed: None,
}
.execute(&mut rpc, &payer, &payer)
.await?;
// Create associated token account
let (_signature, associated_token_account) = CreateAta {
mint,
owner: payer.pubkey(),
idempotent: true,
}
.execute(&mut rpc, &payer)
.await?;
// Mint tokens (payer is mint authority)
let sig = MintTo {
mint,
destination: associated_token_account,
amount: 1_000_000,
}
.execute(&mut rpc, &payer, &payer)
.await?;
let data = rpc.get_account(associated_token_account).await?.ok_or("Account not found")?;
let token = light_token_interface::state::Token::deserialize(&mut &data.data[..])?;
println!("Balance: {} Tx: {sig}", token.amount);
Ok(())
}