Spl token rust. Let us know if it turns out to be a bug in Cargo and we will revisit. 330KB 8K SLoC Token program. Therefore, you must understand the workings of SPL tokens to move further in the journey of Solana development. Function. Constants. 1. Once you have Rust installed, run: Dec 11, 2023 · 10 min read. Based on the extension you want to create, your command flags may be different. You can both get the address and send tokens with the following example. 9 Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide However, users of these types should never have to worry about account substitution attacks. "@solana/spl-token": "^0. 0 dev; test-case ^3. solana. get_associated_token_address. Creates a RecoverNested instruction. state: State transition types . More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects. is_initialized_account. Creates a ‘deposit_all_token_types’ instruction. rs crate page Links; Repository Jul 13, 2022 · The other answers are Rust implementations. Command-line Utility The spl-token-upgrade command-line utility can be used to manage token upgrades. An Account is required to be rent-exempt, so the value is used by the Processor to ensure that wrapped SOL accounts do not drop below this threshold. This process is known as Minting. Extension. I found the spl_token sdk but it only has functions to convert from a balance to a ui balance. To build these, you can run: BUILD_DEPENDENT_PROGRAMS=1 cargo build. Mar 20, 2024 · In your instruction logic: let token_amount = ctx. So first, transfer the ownership to your program-derived address: spl-token authorize <WALLET_2_ADDRESS> owner <PROGRAM_DERIVED_ADDRESS> Jun 22, 2022 · While invoking mpl_token_metadata::instruction::mint_new_edition_from_master_edition_via_token instruction, I found out that it requires both metadata and metadata_mint field as arguments. Jan 18, 2012 · API documentation for the Rust `spl_token` mod in crate `solana_tokens`. API documentation for the Rust `spl_token_cli` crate. delegated_amount: u64. Dec 7, 2023 · SPL tokens are created by interacting with the smart contract facility of the Solana blockchain through pieces of code developed using the Solana blockchain’s programming language (Rust). 3 normal optional ; Jan 18, 2024 · To get started creating tokens with token extensions, you can use the Solana Tool Suite to create tokens with a CLI. Builds. Checks that the supplied program ID is the correct one for SPL-token. js) Using Solana's SPL Token Program API ( Jump to SPL Token Program) This project contains examples of common scripts for SPL Tokens on Solana in Rust. The reverse mullett model of software engineering Apr 14, 2022 · The SPL token account (associated or not) is owned by the SPL token program, which means that only the SPL token program can change its data and deduct its lamports. I would really appreciate some help, thanks! API documentation for the Rust `transfer` fn in crate `anchor_spl`. clap_app. cargo install spl-token-cli Create Token# Creating a new token is simple, make sure your wallet is funded with SOL and just run: spl-token create-token Your token’s address will be printed on screen. memomemo. I created simple program in solana which can transfer,burn and had many other functionalities. 3. useAccountByMint. is_some, this is a native token, and the value logs the rent-exempt reserve. Accounts expected by this instruction: [writeable,signer] Funding account (must be a system account) [writeable] Associated token account address to be created. rs crate page Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide 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; Subscribe to events; The scripts are found in the src/bin folder. Installation. For example, if a program expects a Mint account from the SPL token program in a particular field, then it should be impossible for this method to return Ok if any Jan 8, 2024 · It is also important to remember that the process for Anchor SPL token transfer is different from transferring SOL tokens. The amount delegated. Feb 10, 2024 · How to transfer SPL-tokens using Rust. So, let's add some SPL Token program-related library files to the project before jumping into the SPL token code. rs crate page Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide Implementations should be unique to a particular account type so that one can never successfully deserialize the data of one account type into another. Returns the program ID. rs crate page Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide Functions. 4. A Token Metadata program for the Solana blockchain. I think the problem is the first account created is not a token account, so even though the mint works, there is no balance increase. proof_generation. 0 Rust website The Book Standard Library API Reference Rust by Example Functions. Follow this answer to receive notifications. Crate anchor_splCopy item path. Convention for associating token accounts with a user wallet. Below are the flags to add to create tokens with each type of extension. [ −] pub fn get_associated_token_address(. The Token functionality will always apply to Token-2022. For example, if a program expects a Mint account from the SPL token program in a particular field, then it should be impossible for this method to return Ok if any other account type is given–from the SPL token program or elsewhere. They can be configured using environment What do I need to get started with SPL-Tokens? Every time you interact with tokens on Solana, you are actually interacting with the Solana Program Library Token, or SPL-Token standard. Step 1: Create Library Files Create a folder, libraries, in The tokens are moved from the nested associated token account to the wallet’s associated token account, and the nested account lamports are moved to the wallet. Dec 11, 2021 · So you just created a new token and you want to airdrop them to early supporters, but let's say you have a lot of people to send the token to, trust me, it'll take a long while to send the token to all those people, so let's automate that! First lets go through a quick guide on how to create spl tokens. Read more I want to transfer my custom SPL-token programmatically from my vault (source token account) to George (user destination token account), where the transaction caller-payer is George. NOTE: Solana enforces transaction size limits, so you'll need to batch the account closures. TODO actually pack / unpack instead of relying on normal memory layout. Feature flags. State transition types. One of the crucial aspects of understanding SPL tokens would focus on an overview of SPL token accounts. Run spl-stake-pool --help for a full description of available commands. API documentation for the Rust `token` mod in crate `anchor_spl`. Functions. cargo/config. dApps nowadays usually do 10 at a time. For example, if a program expects a Mint account from the SPL token program in a particular field, then it should be impossible for this method to return Ok if any Oct 6, 2023 · You will also need the mint address of the token you want to query. Try to convert a UI representation of a token amount to its raw amount using the given decimals field. :: get_associated_token_address. is_native: COption < u64 >. " GitHub is where people build software. spl-token ^4 normal; spl-token-2022 ^0. API documentation for the Rust `anchor_spl_token` crate. try_ui_amount_into_amount. spl-associated-token-account 3. Despite reading the https://docs. I also include one function which accept the sol native currency and after sucessful deposit it can transfer spl-token with respect with sol Aug 16, 2021 · Use the token program to initialise the account as a WRAPPED_SOL_ACCOUNT. You switched accounts on another tab or window. state: State transition types Apr 4, 2024 · Check . Share. The SPL-Token standard requires a specific library to be used, which you can find below based on your language. Hence, I must use a PDA, but I'm struggling to create and invoke my PDA correctly. CLI Flag. 12 Permalink May 16, 2023 · I am trying to test out the spl token 2022 program to make a token with the transfer fee extentsion. Nov 16, 2021 · When someone wants to transfer tokens to a particular user, they do it in 2 steps to enforce safety. src/hooks. option: A C representation of Rust's std::option::Option used accross the FFI boundary for Solana program interfaces. To mint an SPL token, you can write the code from scratch or modify the codebase for an existing SPL token. 3 normal optional ; Returns the validated accounts struct. As others implement Sealevel, we will graciously accept patches to ensure the Jan 5, 2023 · I've been learning Rust and piecing together some code that will mint 1 spl-token. Source. Problem error: failed to compile spl-token-cli v3. Reload to refresh your session. let check_mint = ctx. First, they deposit those tokens into an escrow token account that is controlled by our program. , Solana Explorer: In your terminal, fetch your token account by entering: spl-token address --owner OWNER_WALLET_ADDRESS --token TOKEN_MINT_ADDRESS --verbose -um. Once you have Rust installed, run: $ cargo install spl-stake-pool-cli. To associate your repository with the spl-token topic, visit your repo's landing page and select "manage topics. Solana Program Library Associated Token Account. In order to send a SPL token, you need to know its SPL token account address. check_program_account. API documentation for the Rust `spl_token` crate. 12. Apache-2. toml in order to include the Certora library that contains all the functionality to create fresh environments as well as special functions to write the pre- and post-conditions Can be used as a check or with init to create a token account with the given mint address and authority. My script compiles, creates an account, initializes a mint, creates the associated token account, and mints 1 token to this account. 3 normal optional ; Mar 15, 2024 · Install spl-token-cli# Now using Rust we are gonna install Solana’s CLI tools, this will take a few minutes. token. The Overflow Blog Upcoming research at Stack Overflow. TS. For example, if the SPL token program were to implement this trait, it should be impossible to deserialize a Mint account into a token Account. dexdex. Anchor CPI wrappers for popular programs in the Solana ecosystem. spl-token-4. spl_associated_token_account. 0". Security Audits The Token-2022 Program has been audited multiple times. Source The Token-2022 Program's source is available on GitHub. check_id. amount; // pulls token account balance. You can find this by searching for the name of the token on any Solana-based explorer, e. 1 SOL to a address and for that Acc1 receives 1 SPL-TOKEN from that address. Namespace for all programs implementing token-metadata. Note: Nested token accounts are an anti-pattern, and almost always created unintentionally, so this instruction should only be used to recover from errors. rs. 2. Docs. As others implement Sealevel, we will graciously accept patches to ensure the programs here are portable Mar 2, 2023 · spl-token; rust; accountinfo; or ask your own question. io and docs. Use the Token Program open in new window to transfer SPL Tokens. NAMESPACE. For information about the types and instructions, the Rust docs are available at docs. governancegovernance. This is checking the state (AccountState) field of an Account object. rs file, which can be error-prone, so alternatively, you can build the programs by running the following commands from this directory: API documentation for the Rust `Token2022` struct in crate `anchor_spl`. [] Wallet address for the new associated token account. Returns true if given pubkey is the program ID. anchor-spl-token-0. ui_amount_to_amount. Available on crate feature associated_token only. Creates a ‘deposit_single_token_type_exact_amount_in’ instruction. create_associated_token_account_idempotent. associated_tokenassociated_token. Here's a Typescript one for browsers/Node applications using @solana/web3. API documentation for the Rust `associated_token` mod in crate `anchor_spl`. anchor-spl-token 0. API documentation for the Rust `approve` fn in crate `anchor_spl`. Creates a ‘swap’ instruction. balanceLamports. Operational Aug 13, 2023 · Compile SPL Token 2022 and Usage of SCP. processor: Program entrypoint definitions. Mar 10, 2022 · To transfer an SPL token within a program, your best option is to have wallet A owned by a program-derived address, and then your program can transfer the tokens from wallet A based on any logic it wants. Second, the final receiver of the tokens confirms the withdrawal and receives the funds from the escrow. The tests require locally built programs for Token, Token-2022, and Associated Token Account. What constitutes “valid” is program dependent. Overview . 3 Permalink Docs. The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime . Interface The Token Upgrade Program is written in Rust and available on crates. 8. Full SPL Flow (Create Token, Mint Token, Transfer Token) cargo run --bin spl_flow spl-token-metadata-interface 0. API documentation for the Rust `spl_token_client` crate. Simple explanation: I need a minting website for a token. Jan 5, 2022 · Acc1 sends 0. payer_token_account. 18. 2 Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide Clippy Documentation Created FT spl-token with rust smart contract in solana with the help of questbook. source· [−] Modules§. source ·. Viewed 115 times 0 I want to add to my smart-contract tranfer SPL-tokens spl-associated-token-account 3. What I have: spl-token-2022 ^0. Check if the account data buffer represents an initialized account. When contract A calls contract B internally, the user’s signature will spread to contract B along with the cross-contract call. wallet_address: & Pubkey , token_mint_address: & Pubkey. I saw that an account has an amount field but this seems to be for the SOL amount or am I wrong? Derives the associated token account address for the given wallet address, token mint and token program id. 3 normal optional ; Type Aliases. Confirms that a given pubkey is equivalent to the program ID. Helper functions to generate split zero-knowledge proofs for confidential transfers. ) -> Pubkey. The crate provides four instructions, create_metadata_account(), update_metadata_account(), create_master_edition(), mint_new_edition_from_master_edition_via_token(), to easily create instructions for the program. Crate defining an interface for token-metadata. useUserTotalBalance - aggregates user balance across all token accounts and returns value in USD. Derives the associated token account address for the given wallet address and token mint. Creates CreateIdempotent instruction. Crate. Transfer the wrapped SOL (or in your case, you may just want to call the program and put the wrapped SOL account as a parameter) Close the Wrapped SOL account so that the user gets back their rent. js and @solana/spl-token (v0. You signed out in another tab or window. Unlike #1, #2, #3, I'm coding in native Solana Rust - NO Anchor. Documentation. accounts. create_associated_token_account. Derives the associated token account address for the given wallet address and Jan 31, 2024 · As the SPL Token program is written in Rust, not Solidity, some library files are needed to establish the communication between the Solidity code and the SPL Token program. Creates Create instruction. rs crate page Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide output. mint; // pulls associated mint, should match "token_mint". 2 Permalink Docs. ExtensionsVec. command. The spl-stake-pool command-line utility can be used to experiment with SPL tokens. If is_native. create_associated_token_account Deprecated. amount_to_ui_amount: Convert a raw amount to its UI representation (using the decimals field defined in its mint) check_id: Confirms that a given pubkey is equivalent to the program ID Mar 28, 2024 · Solana Program Library. c Feb 5, 2024 · Solana Program Library Token | Rust/Cargo package. So far I have the following: let extension_types = vec![spl_token_2022::extension::ExtensionType:: Mar 22, 2022 · The MintTo instruction takes three user-supplied accounts:. The Token Upgrade Program's source is available on GitHub. Crate spl_token_cli. toml or run cargo +nightly -Zunstable-options config get source --show-origin to find where it is set. 0, intermediate artifacts can be found at You signed in with another tab or window. Close as it is likely to be a misconfiguration slipping in. The user calls contract A, and the user in contract A has signed and approved it. The Mint that represents the native token. Creates an ‘initialize’ instruction. Returns the validated accounts struct. An Uniswap-like program for the Solana blockchain. Generic react hooks to interact with token program: useUserBalance - query for balance of any user token by mint, returns: balance. recover_nested. Otherwise, it would be possible for anyone to bring a token account under rent-exemption and break guarantees of the token program. Example: use anchor_spl::{mint, token::{TokenAccount, Mint, Token}}; Nov 30, 2022 · It is possible to create a custom SPL-token and disabling the trade and send capabilities for the user (not for the SPL-token authority)? The idea is to create a token that can only be purchased and spent within our specific application and at the same time maintain all the benefits of an SPL-token. 0):. Therefore, in contract B, the user is The account’s state. 1. # How to send SPL-Tokens. Modules§. Sep 22, 2022 · I wanted to inquire if anybody knows how to tranfer a spl-token from an account when the account receives a SOL because I'm a novice Rust/Solana developer. Since SPL Token 2022 is written in Rust, to compile the application with our verification harness, we first need to modify Cargo. 1 Permalink Docs. mint_info: the mint account (line 523); destination_account_info: the token account to mint tokens to (line 524); owner_info: the mint The Rust/Cargo programs are licensed under the "Apache-style" Metaplex(TM) NFT Open Source License and the JS/TS client libraries are licensed under either the MIT or the Apache licenses. Ask Question Asked 2 months ago. Create an associated token account for the given wallet address and token mint. About Program to attach additional data to Fungible or Non-Fungible tokens on Solana. Sending Solana Program Library (SPL) Tokens is a critical mechanism for Solana development. id. spl-token-group-interface ^0. Mar 28, 2024 · The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime . config. Whereas, on the metaplex documentation, it seems the instruction only requires the Master record metadata account. g. When used as a check, it's possible to only specify a subset of the constraints. Program instructions. Whether you are airdropping whitelist tokens to your community, bulk sending NFTs to another wallet, or managing token flows between escrow accounts, you will inevitably need to be able to transfer SPL tokens. io as spl-token-metadata and docs. spl-token-2022 3. Improve this answer. Convert the UI representation of a token amount (using the decimals field defined in its mint) to the raw amount. 0. This method uses the local build. 159,081 downloads per month Used in 613 crates (274 directly). In Solana, there is a signature diffusion mechanism. A token program on the Solana blockchain, usable for fungible and non-fungible tokens. Signature Diffusion Mechanism in Solana. However, users of these types should never have to worry about account substitution attacks. source· [−] Expand description. Unpacks a reference from a bytes buffer. For existing functionality in the Token Program, see the token docs. Modified 1 month ago. spl-token 4. API documentation for the Rust `token_interface` mod in crate `anchor_spl`. For example, if a program expects a Mint account from the SPL token program in a particular field, then it should be impossible for this method to return Ok if any Aug 31, 2022 · Within my Rust program I would like to get the mint token balance of an account. These programs are tested against Solana's implementation of Sealevel, solana-runtime, and some are deployed to Mainnet Beta. For example, if a program expects a Mint account from the SPL token program in a particular field, then it should be impossible for this method to return Ok if any Oct 6, 2023 · In this guide, we will walk through five easy ways to check the balance of an SPL token account: Using Solana's SPL-Token Command Line Interface (SPL-Token CLI) ( Jump to SPL-Token CLI) Using Solana's JavaScript API ( Jump to Solana-Web3. balanceInUSD. You can read the spl docs here Aug 14, 2021 · The on-chain Token Metadata program is written in Rust and available on crates. spl-token-2022-3. cu fh dg ta jq ue aj nd ro vi