Solana Scripts
This is a library of Rust scripts for specific purposes:
- Generate a new wallet
- Create an SPL token
- Mint an SPL token
- Get an associated token balance
- Get the creation date of an account
- Get the owner of an NFT
- List NFTs in wallet
- Print NFT metadata
The scripts are found in the src/bin
folder. They can be configured using environment variables, which are documented below.
Open an issue if you have any requests or suggestions.
New wallet
cargo run --bin new_wallet
| Code
Generates a new wallet and prints the pubkey, Base58 private key, and JSON private key.
Create an SPL token
cargo run --bin create_spl
| Code
Creates a new SPL token mint account.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
SIGNER_KEYPAIR | Base58 encoded keypair, to pay for the transaction. |
MINT_KEYPAIR | Base58 encoded keypair, representing the new mint account. |
Mint SPL tokens
cargo run --bin mint_spl
| Code
Mints 10,000 SPL tokens from a specified mint to the associated token account of a specified wallet.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
SIGNER_KEYPAIR | Base58 encoded keypair, which has mint authority. |
MINT_ACCOUNT_PUBKEY | The pubkey address of the SPL Token mint account. |
RECEIVER_PUBKEY | The pubkey address of the wallet you want to fund with the tokens. |
Get token balance
cargo run --bin associated_token_balance
| Code
Prints the balance of an associated token account, for a specified wallet and mint.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
WALLET_PUBKEY | The pubkey address of the wallet that owns the tokens. |
MINT_ACCOUNT_PUBKEY | The pubkey address of the SPL Token mint account. |
Get account creation timestamp
cargo run --bin creation_date
| Code
Fetches and prints the creation timestamp of a specified account.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
ACCOUNT_PUBKEY | The pubkey address of the account you want to introspect. |
Get NFT owner
cargo run --bin nft_owner
| Code
Prints the wallet address that owns a specified NFT.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
MINT_ACCOUNT_PUBKEY | The pubkey address of the SPL Token mint account. |
List NFTs in wallet
cargo run --bin list_nfts
| Code
Fetches and prints the mint pubkeys of every NFT in the specified wallet.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
WALLET_PUBKEY | The pubkey address of the wallet that owns the NFTs. |
Print NFT metadata
cargo run --bin print_nft
| Code
Fetches, decodes and prints the metadata of the specified NFT.
Environment Variable | Note |
---|---|
RPC_URL | e.g. https://api.mainnet-beta.solana.com |
MINT_ACCOUNT_PUBKEY | The pubkey of the NFT's SPL Token mint account. |