SPL Name Service decoder
Decode SPL Name Service instructions and accounts in Rust with carbon-name-service-decoder 2.0.0. Program ID namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX.
On this page
carbon-name-service-decoder decodes the instructions and accounts of the SPL Name Service program (namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX): 5 instructions, 1 account type. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.
| Crate | carbon-name-service-decoder 2.0.0 |
| Install | cargo add carbon-name-service-decoder@2. |
| Program ID | namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX (carbon_) |
| Category | Core & SPL |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-name-service-decoder/2.0.0 |
| Source | decoders/name-service-decoder |
Other core and SPL decoders: Address Lookup Table, Associated Token Account, SPL Memo, SPL Token, Stake Program, System Program, Token-2022. To decode several in one pipeline, see core and SPL program decoders.
The serde feature derives Serialize/Deserialize on every type, postgres adds tables and processors for Postgres, and graphql adds a schema for the GraphQL server.
Usage#
This program crawls recent SPL Name Service transactions from the public RPC and prints every decoded Create instruction. Add the dependencies:
cargo add carbon-core@2.0.0 carbon-name-service-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/fulluse {
carbon_core::{
error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_name_service_decoder::{
instructions::NameServiceInstruction, NameServiceDecoder, PROGRAM_ID,
},
carbon_rpc_transaction_crawler_datasource::{ConnectionConfig, Filters, RpcTransactionCrawler},
std::sync::Arc,
};
#[tokio::main]
async fn main() -> CarbonResult<()> {
env_logger::init();
// Fetches the program's recent transactions over JSON-RPC, newest first.
let datasource = RpcTransactionCrawler::new(
"https://api.mainnet-beta.solana.com".to_string(),
PROGRAM_ID,
ConnectionConfig::default(),
Filters::new(None, None, None),
None,
);
Pipeline::builder()
.datasource(datasource)
.metrics(Arc::new(LogMetrics::new()))
.instruction(NameServiceDecoder, InstructionLogger)
.build()?
.run()
.await
}
struct InstructionLogger;
impl Processor<InstructionProcessorInputType<'_, NameServiceInstruction>> for InstructionLogger {
async fn process(
&mut self,
input: &InstructionProcessorInputType<'_, NameServiceInstruction>,
) -> CarbonResult<()> {
let signature = input.metadata.transaction_metadata.signature;
if let NameServiceInstruction::Create { data, accounts, .. } = input.decoded_instruction {
println!("create {signature}: {data:?} system_program={}", accounts.system_program);
}
Ok(())
}
}RUST_LOG=info cargo runEach Create instruction prints one line with the transaction signature and the decoded Create data. The public endpoint rate-limits requests, so the first lines can take a while; use your own RPC URL for anything beyond a test. See stream with RPC for the crawler options.
Decode accounts#
The transaction crawler emits transactions only. To decode accounts, use a datasource that emits account updates. This program subscribes to the program's accounts with programSubscribe on the public WebSocket endpoint and prints every decoded NameRecordHeader account as it changes. Add the datasource and the Solana RPC types it takes:
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2use {
carbon_core::{
account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_name_service_decoder::{accounts::NameServiceAccount, NameServiceDecoder, PROGRAM_ID},
carbon_rpc_program_subscribe_datasource::{Filters, RpcProgramSubscribe},
solana_client::rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, UiAccountEncoding},
std::sync::Arc,
};
#[tokio::main]
async fn main() -> CarbonResult<()> {
env_logger::init();
// Streams every change to an account owned by the program (programSubscribe).
let config = RpcProgramAccountsConfig {
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
..Default::default()
},
..Default::default()
};
let datasource = RpcProgramSubscribe::new(
"wss://api.mainnet-beta.solana.com".to_string(),
Filters::new(PROGRAM_ID, Some(config)),
);
Pipeline::builder()
.datasource(datasource)
.metrics(Arc::new(LogMetrics::new()))
.account(NameServiceDecoder, AccountLogger)
.build()?
.run()
.await
}
struct AccountLogger;
impl Processor<AccountProcessorInputType<'_, NameServiceAccount>> for AccountLogger {
async fn process(
&mut self,
input: &AccountProcessorInputType<'_, NameServiceAccount>,
) -> CarbonResult<()> {
let NameServiceAccount::NameRecordHeader(name_record_header) = &input.decoded_account.data;
println!("name_record_header {}: {name_record_header:?}", input.metadata.pubkey);
Ok(())
}
}RUST_LOG=info cargo runEach update to a NameRecordHeader account prints its address and decoded fields; the program runs until you stop it. Cargo resolves solana-client to 4.2.2, the exact version the datasource pins, so both use the same RpcProgramAccountsConfig type. To load every existing account once instead of streaming changes, see load account state.
Instructions#
Variants of NameServiceInstruction. Each is NameServiceInstruction::, where data and accounts are the types listed under the variant, exported from carbon_. Discriminators are the leading bytes of the instruction data, in hex.
How an instruction decodes. The decoder returns a variant only when all of these hold; otherwise the instruction is skipped and no processor is called:
- The instruction's program ID is
namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX. - The data starts with the variant's discriminator, and the rest deserializes into its data type.
- The instruction has at least as many accounts as the variant requires (the "Required accounts" count under each variant).
Accounts. They are matched by position, in the order listed. An account marked optional is None only when the instruction ends before it; Anchor programs pass the program ID as a placeholder for an omitted optional account, so check for Some(PROGRAM_ too. Accounts after the listed ones are in accounts. as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input. and ., which follow the same order. It doesn't check signer, writable, owner or PDA constraints either; the program enforced those when the transaction executed, so a decoded instruction from a successful transaction already satisfied them.
Create#
Discriminator 00 · data Create · accounts CreateInstructionAccounts.
| Field | Type |
|---|---|
hashed_name | Vec<u8> |
lamports | u64 |
space | u32 |
Required accounts: 6; extras go to remaining.
Fields of CreateInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | system_ | Pubkey |
| 1 | funding_ | Pubkey |
| 2 | name_record | Pubkey |
| 3 | account_ | Pubkey |
| 4 | parent_ | Pubkey |
| 5 | parent_ | Pubkey |
| 6… | remaining | Vec< |
Delete#
Discriminator 03 · data Delete · accounts DeleteInstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of DeleteInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | name_record | Pubkey |
| 1 | owner | Pubkey |
| 2 | refund_ | Pubkey |
| 3… | remaining | Vec< |
Realloc#
Discriminator 04 · data Realloc · accounts ReallocInstructionAccounts.
| Field | Type |
|---|---|
space | u32 |
Required accounts: 4; extras go to remaining.
Fields of ReallocInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | system_ | Pubkey |
| 1 | payer | Pubkey |
| 2 | name_record | Pubkey |
| 3 | owner | Pubkey |
| 4… | remaining | Vec< |
Transfer#
Discriminator 02 · data Transfer · accounts TransferInstructionAccounts.
| Field | Type |
|---|---|
new_owner | Pubkey |
Required accounts: 3; extras go to remaining.
Fields of TransferInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | name_record | Pubkey |
| 1 | owner | Pubkey |
| 2 | parent_ | Pubkey |
| 3… | remaining | Vec< |
Update#
Discriminator 01 · data Update · accounts UpdateInstructionAccounts.
| Field | Type |
|---|---|
offset | u32 |
data | Vec<u8> |
Required accounts: 3; extras go to remaining.
Fields of UpdateInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | name_record | Pubkey |
| 1 | owner | Pubkey |
| 2 | parent_ | Pubkey |
| 3… | remaining | Vec< |
Accounts#
Variants of NameServiceAccount. Each wraps a boxed struct from carbon_. decode_ only considers accounts owned by PROGRAM_ID and returns the first variant that matches.
NameRecordHeader#
No discriminator (matched by Borsh layout) · accounts::.
| Field | Type |
|---|---|
parent_name | Pubkey |
owner | Pubkey |
class | Pubkey |