Documentation
¶
Index ¶
- Constants
- Variables
- func DecimalsInBigInt(decimal uint32) *big.Int
- func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, data []byte) (any, error)
- func GetAddedRemovedPubkeys(previous PublicKeySlice, next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)
- func IsAnyOfEncodingType(candidate EncodingType, allowed ...EncodingType) bool
- func IsOnCurve(b []byte) bool
- func IsSanitizeError(err error) bool
- func LamportsPerSignatureOf(data []byte) (uint64, bool)
- func MustRegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)
- func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder) error
- func ValidatePrivateKey(b []byte) (bool, error)
- type Account
- type AccountMeta
- type AccountMetaSlice
- func (slice *AccountMetaSlice) Append(account *AccountMeta)
- func (slice AccountMetaSlice) Get(index int) *AccountMeta
- func (slice AccountMetaSlice) GetAccounts() []*AccountMeta
- func (slice AccountMetaSlice) GetKeys() PublicKeySlice
- func (slice AccountMetaSlice) GetSigners() []*AccountMeta
- func (slice AccountMetaSlice) Len() int
- func (slice *AccountMetaSlice) SetAccounts(accounts []*AccountMeta) error
- func (slice AccountMetaSlice) SplitFrom(index int) (AccountMetaSlice, AccountMetaSlice)
- type AccountsGettable
- type AccountsSettable
- type Base58
- type Base64
- type ByteWrapper
- type CompiledInstruction
- type Data
- type DurableNonce
- type DurationMilliseconds
- type DurationSeconds
- type EncodingType
- type Feature
- type FeatureSet
- type FeeCalculator
- type GenericInstruction
- type Hash
- type Instruction
- type InstructionDecoder
- type Message
- func (m *Message) Account(index uint16) (PublicKey, error)
- func (m *Message) AccountMetaList() (AccountMetaSlice, error)
- func (mx *Message) AddAddressTableLookup(lookup MessageAddressTableLookup) *Message
- func (mx *Message) EncodeToTree(txTree treeout.Branches)
- func (m *Message) GetAccountIndex(account PublicKey) (uint16, error)
- func (mx *Message) GetAddressTableLookupAccounts() (PublicKeySlice, error)
- func (mx *Message) GetAddressTableLookups() MessageAddressTableLookupSlice
- func (mx *Message) GetAddressTables() map[PublicKey]PublicKeySlice
- func (mx *Message) GetAllKeys() (keys PublicKeySlice, err error)
- func (m *Message) GetIxSigners(ixIndex int) PublicKeySlice
- func (m *Message) GetVersion() MessageVersion
- func (m *Message) HasAccount(account PublicKey) (bool, error)
- func (m *Message) HasDuplicates() bool
- func (m *Message) IsInstructionAccount(index uint16) bool
- func (mx *Message) IsResolved() bool
- func (m *Message) IsSigner(account PublicKey) bool
- func (m *Message) IsVersioned() bool
- func (m *Message) IsWritable(account PublicKey) (bool, error)
- func (m *Message) IsWritableStatic(account PublicKey) bool
- func (mx *Message) MarshalBinary() ([]byte, error)
- func (mx Message) MarshalJSON() ([]byte, error)
- func (mx *Message) MarshalLegacy() ([]byte, error)
- func (mx *Message) MarshalV0() ([]byte, error)
- func (mx *Message) MarshalV1() ([]byte, error)
- func (mx Message) MarshalWithEncoder(encoder *bin.Encoder) error
- func (mx *Message) NumLookups() int
- func (m *Message) NumReadonlyAccounts() int
- func (mx *Message) NumWritableLookups() int
- func (m *Message) Program(programIDIndex uint16) (PublicKey, error)
- func (m *Message) ProgramIDs() PublicKeySlice
- func (m *Message) ProgramPosition(index uint16) (int, bool)
- func (mx *Message) ResolveLookups() (err error)
- func (mx *Message) ResolveLookupsWith(writable, readonly PublicKeySlice) (err error)
- func (m *Message) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)
- func (m *Message) Sanitize() error
- func (mx *Message) SetAddressTableLookups(lookups []MessageAddressTableLookup) *Message
- func (mx *Message) SetAddressTables(tables map[PublicKey]PublicKeySlice) error
- func (m *Message) SetVersion(version MessageVersion) (*Message, error)
- func (m *Message) Signers() PublicKeySlice
- func (mx Message) ToBase64() string
- func (mx *Message) UnmarshalBase64(b64 string) error
- func (mx *Message) UnmarshalJSON(data []byte) error
- func (mx *Message) UnmarshalLegacy(decoder *bin.Decoder) (err error)
- func (mx *Message) UnmarshalV0(decoder *bin.Decoder) (err error)
- func (mx *Message) UnmarshalV1(decoder *bin.Decoder) (err error)
- func (mx *Message) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
- func (m *Message) Writable() (out PublicKeySlice, err error)
- type MessageAddressTableLookup
- type MessageAddressTableLookupSlice
- type MessageHeader
- type MessageVersion
- type MissingRequiredSignatureError
- type NonceData
- type NonceState
- type NonceStateKind
- type NonceVersion
- type NonceVersions
- func (v NonceVersions) Authorize(signers []PublicKey, newAuthority PublicKey) (NonceVersions, error)
- func (v NonceVersions) LamportsPerSignature() (uint64, bool)
- func (v NonceVersions) MarshalAccountData() ([]byte, error)
- func (v NonceVersions) MarshalBinary() ([]byte, error)
- func (v NonceVersions) MarshalWithEncoder(encoder *bin.Encoder) (err error)
- func (v *NonceVersions) UnmarshalBinary(data []byte) error
- func (v *NonceVersions) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
- func (v NonceVersions) Upgrade() (NonceVersions, bool)
- func (v NonceVersions) VerifyRecentBlockhash(recentBlockhash Hash) (*NonceData, bool)
- type PK
- type Padding
- type PrivateKey
- func MustPrivateKeyFromBase58(in string) PrivateKey
- func NewRandomPrivateKey() (PrivateKey, error)
- func PrivateKeyFromBase58(privkey string) (PrivateKey, error)
- func PrivateKeyFromMnemonic(mnemonic, passphrase string) (PrivateKey, error)
- func PrivateKeyFromMnemonicAtPath(mnemonic, passphrase, path string) (PrivateKey, error)
- func PrivateKeyFromSeedAtPath(seed []byte, path string) (PrivateKey, error)
- func PrivateKeyFromSolanaKeygenFile(file string) (PrivateKey, error)
- func PrivateKeyFromSolanaKeygenFileBytes(content []byte) (PrivateKey, error)
- type PublicKey
- func CreateProgramAddress(seeds [][]byte, programID PublicKey) (PublicKey, error)
- func CreateWithSeed(base PublicKey, seed string, owner PublicKey) (PublicKey, error)
- func FindAssociatedTokenAddress(wallet PublicKey, mint PublicKey) (PublicKey, uint8, error)
- func FindAssociatedTokenAddressWithProgram(wallet PublicKey, mint PublicKey, tokenProgram PublicKey) (PublicKey, uint8, error)
- func FindProgramAddress(seed [][]byte, programID PublicKey) (PublicKey, uint8, error)
- func FindTokenMetadataAddress(mint PublicKey) (PublicKey, uint8, error)
- func GetAssociatedAuthority(programID PublicKey, marketAddr PublicKey) (PublicKey, uint8, error)
- func MPK(in string) PublicKey
- func MustPublicKeyFromBase58(in string) PublicKey
- func PublicKeyFromBase58(in string) (out PublicKey, err error)
- func PublicKeyFromBytes(in []byte) (out PublicKey)
- func (p PublicKey) Bytes() []byte
- func (p PublicKey) Equals(pb PublicKey) bool
- func (p PublicKey) IsAnyOf(keys ...PublicKey) bool
- func (p PublicKey) IsOnCurve() bool
- func (p PublicKey) IsZero() bool
- func (p PublicKey) MarshalBSON() ([]byte, error)
- func (p PublicKey) MarshalBSONValue() (bson.Type, []byte, error)
- func (p PublicKey) MarshalJSON() ([]byte, error)
- func (p PublicKey) MarshalText() ([]byte, error)
- func (p *PublicKey) Set(s string) (err error)
- func (p PublicKey) Short(n int) string
- func (p PublicKey) String() string
- func (p PublicKey) ToPointer() *PublicKey
- func (p *PublicKey) UnmarshalBSON(data []byte) (err error)
- func (p *PublicKey) UnmarshalBSONValue(t bson.Type, data []byte) (err error)
- func (p *PublicKey) UnmarshalJSON(data []byte) (err error)
- func (p *PublicKey) UnmarshalText(data []byte) error
- func (p PublicKey) Verify(message []byte, signature Signature) bool
- type PublicKeySlice
- func (a PublicKeySlice) Added(b PublicKeySlice) PublicKeySlice
- func (slice *PublicKeySlice) Append(pubkeys ...PublicKey)
- func (slice PublicKeySlice) Contains(pubkey PublicKey) bool
- func (slice PublicKeySlice) ContainsAll(pubkeys PublicKeySlice) bool
- func (slice PublicKeySlice) ContainsAny(pubkeys ...PublicKey) bool
- func (slice PublicKeySlice) Dedupe() PublicKeySlice
- func (slice PublicKeySlice) Equals(other PublicKeySlice) bool
- func (slice PublicKeySlice) First() *PublicKey
- func (prev PublicKeySlice) GetAddedRemoved(next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)
- func (slice PublicKeySlice) Has(pubkey PublicKey) bool
- func (prev PublicKeySlice) Intersect(next PublicKeySlice) PublicKeySlice
- func (slice PublicKeySlice) Last() *PublicKey
- func (slice PublicKeySlice) Len() int
- func (slice PublicKeySlice) Less(i, j int) bool
- func (a PublicKeySlice) Removed(b PublicKeySlice) PublicKeySlice
- func (slice PublicKeySlice) Same(other PublicKeySlice) bool
- func (slice PublicKeySlice) Sort()
- func (slice PublicKeySlice) Split(chunkSize int) []PublicKeySlice
- func (slice PublicKeySlice) Swap(i, j int)
- func (slice PublicKeySlice) ToBase58() []string
- func (slice PublicKeySlice) ToBytes() [][]byte
- func (slice PublicKeySlice) ToPointers() []*PublicKey
- func (slice *PublicKeySlice) UniqueAppend(pubkey PublicKey) bool
- type Signature
- func (sig Signature) Equals(pb Signature) bool
- func (sig Signature) IsZero() bool
- func (p Signature) MarshalJSON() ([]byte, error)
- func (p Signature) MarshalText() ([]byte, error)
- func (p Signature) String() string
- func (p *Signature) UnmarshalJSON(data []byte) (err error)
- func (p *Signature) UnmarshalText(data []byte) (err error)
- func (s Signature) Verify(pubkey PublicKey, msg []byte) bool
- type SystemAccountKind
- type Transaction
- func MustTransactionFromDecoder(decoder *bin.Decoder) *Transaction
- func NewTransaction(instructions []Instruction, recentBlockHash Hash, opts ...TransactionOption) (*Transaction, error)
- func TransactionFromBase58(b58 string) (*Transaction, error)
- func TransactionFromBase64(b64 string) (*Transaction, error)
- func TransactionFromBytes(data []byte) (*Transaction, error)
- func TransactionFromDecoder(decoder *bin.Decoder) (*Transaction, error)
- func (t *Transaction) AccountMetaList() ([]*AccountMeta, error)
- func (tx *Transaction) EncodeToTree(parent treeout.Branches)
- func (tx *Transaction) EncodeTree(encoder *text.TreeEncoder) (int, error)
- func (t *Transaction) GetAccountIndex(account PublicKey) (uint16, error)
- func (tx *Transaction) GetNonceAccount() (PublicKey, bool)
- func (tx *Transaction) GetProgramIDs() (PublicKeySlice, error)
- func (t *Transaction) HasAccount(account PublicKey) (bool, error)
- func (t *Transaction) IsSigner(account PublicKey) bool
- func (tx *Transaction) IsVote() bool
- func (t *Transaction) IsWritable(account PublicKey) (bool, error)
- func (tx *Transaction) MarshalBinary() ([]byte, error)
- func (tx Transaction) MarshalWithEncoder(encoder *bin.Encoder) error
- func (tx Transaction) MustToBase64() string
- func (tx *Transaction) NumReadonlyAccounts() int
- func (tx *Transaction) NumSigners() int
- func (tx *Transaction) NumWriteableAccounts() int
- func (tx *Transaction) PartialSign(getter privateKeyGetter) (out []Signature, err error)
- func (t *Transaction) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)
- func (tx *Transaction) Sanitize() error
- func (tx *Transaction) Sign(getter privateKeyGetter) (out []Signature, err error)
- func (tx *Transaction) String() string
- func (tx Transaction) ToBase64() (string, error)
- func (tx *Transaction) UnmarshalBase64(b64 string) error
- func (tx *Transaction) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
- func (tx *Transaction) UsesDurableNonce() bool
- func (tx *Transaction) VerifySignatures() error
- func (tx *Transaction) VerifyWithResults() ([]bool, error)
- type TransactionBuilder
- func (builder *TransactionBuilder) AddInstruction(instruction Instruction) *TransactionBuilder
- func (builder *TransactionBuilder) Build() (*Transaction, error)
- func (builder *TransactionBuilder) SetFeePayer(feePayer PublicKey) *TransactionBuilder
- func (builder *TransactionBuilder) SetRecentBlockHash(recentBlockHash Hash) *TransactionBuilder
- func (builder *TransactionBuilder) SetTransactionConfig(config TransactionConfig) *TransactionBuilder
- func (builder *TransactionBuilder) SetVersion(version MessageVersion) *TransactionBuilder
- func (builder *TransactionBuilder) WithOpt(opt TransactionOption) *TransactionBuilder
- type TransactionConfig
- func (c *TransactionConfig) EncodeToTree(branch treeout.Branches)
- func (c TransactionConfig) IsEmpty() bool
- func (c TransactionConfig) Mask() TransactionConfigMask
- func (c TransactionConfig) Size() int
- func (c TransactionConfig) WithComputeUnitLimit(units uint32) TransactionConfig
- func (c TransactionConfig) WithHeapSize(bytes uint32) TransactionConfig
- func (c TransactionConfig) WithLoadedAccountsDataSizeLimit(bytes uint32) TransactionConfig
- func (c TransactionConfig) WithPriorityFee(lamports uint64) TransactionConfig
- type TransactionConfigMask
- func (m TransactionConfigMask) HasComputeUnitLimit() bool
- func (m TransactionConfigMask) HasHeapSize() bool
- func (m TransactionConfigMask) HasInvalidPriorityFeeBits() bool
- func (m TransactionConfigMask) HasLoadedAccountsDataSize() bool
- func (m TransactionConfigMask) HasPriorityFee() bool
- func (m TransactionConfigMask) HasUnknownBits() bool
- func (m TransactionConfigMask) SizeOfConfig() int
- type TransactionOption
- type Uint8SliceAsNum
- type UnixTimeMilliseconds
- type UnixTimeSeconds
- type Wallet
Examples ¶
Constants ¶
const ( // There are 1-billion lamports in one SOL. LAMPORTS_PER_SOL uint64 = 1000000000 SolDecimals uint8 = 9 )
const ( // Number of bytes in a pubkey. PublicKeyLength = 32 // Maximum length of derived pubkey seed. MaxSeedLength = 32 // Maximum number of seeds. MaxSeeds = 16 // Number of bytes in a signature. SignatureLength = 64 // Number of bytes in a private key. PrivateKeyLength = voied25519.PrivateKeySize )
const ( // MaxTransactionSizeV1 is the V1 size cap, signatures included (enforced by the cluster). MaxTransactionSizeV1 = 4096 // MaxAddressesV1 is the maximum number of addresses in a V1 message. MaxAddressesV1 = 64 // MaxInstructionsV1 is the maximum number of instructions in a V1 message. MaxInstructionsV1 = 64 // MaxSignaturesV1 is the maximum number of signatures in a V1 transaction. MaxSignaturesV1 = 12 // MinHeapSizeV1 is the minimum (and default) requested heap size. MinHeapSizeV1 uint32 = 32 * 1024 // MaxHeapSizeV1 is the maximum requested heap size. MaxHeapSizeV1 uint32 = 256 * 1024 // DefaultHeapSizeV1 is the heap size when none is requested. DefaultHeapSizeV1 = MinHeapSizeV1 )
const ( AccountsTypeIndex = "Fee" AccountsTypeKey = "Key" )
const FeatureSizeOf = 9
FeatureSizeOf is the serialized size of a Feature account (1-byte option tag + u64).
const NonceStateSize = 80
NonceStateSize is the serialized size, in bytes, of a nonce account's data. It is constant regardless of whether the account is initialized: the runtime always allocates this many bytes. Mirrors solana_nonce::state::State::size().
const PDA_MARKER = "ProgramDerivedAddress"
const SolanaDerivationPath = "m/44'/501'/0'/0'"
SolanaDerivationPath is the default BIP-44 derivation path used by Phantom and most Solana wallets when generating a key from a BIP-39 mnemonic: m/44'/501'/0'/0'.
Variables ¶
var ( FeatureReduceSlotTimeTo350ms = MustPublicKeyFromBase58("iBRL5RuWhw4yqaAZu96RUULHckHTZAoe2b77qaV38JZ") FeatureReduceSlotTimeTo300ms = MustPublicKeyFromBase58("iBRLL3k18HST852F1Mf3Lv83waTNQmmqvKDxvYGwQFL") FeatureReduceSlotTimeTo250ms = MustPublicKeyFromBase58("iBRLMc81UjRa8fn8A6eE8bJTnRbgQoPTynM51akENCV") FeatureReduceSlotTimeTo200ms = MustPublicKeyFromBase58("iBRLjhJnkmDZgNoZRDMW11d8ZV7HvsL3vAyRjZB5npW") )
SIMD-0525 slot-time reduction feature gates, in activation order. Each takes effect one epoch after its activation epoch (see sysvar.MsPerSlotAt).
var ( // Create new accounts, allocate account data, assign accounts to owning programs, // transfer lamports from System Program owned accounts and pay transacation fees. SystemProgramID = MustPublicKeyFromBase58("11111111111111111111111111111111") // Add configuration data to the chain and the list of public keys that are permitted to modify it. ConfigProgramID = MustPublicKeyFromBase58("Config1111111111111111111111111111111111111") // Create and manage accounts representing stake and rewards for delegations to validators. StakeProgramID = MustPublicKeyFromBase58("Stake11111111111111111111111111111111111111") // Create and manage accounts that track validator voting state and rewards. VoteProgramID = MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111") BPFLoaderDeprecatedProgramID = MustPublicKeyFromBase58("BPFLoader1111111111111111111111111111111111") // Deploys, upgrades, and executes programs on the chain. BPFLoaderProgramID = MustPublicKeyFromBase58("BPFLoader2111111111111111111111111111111111") BPFLoaderUpgradeableProgramID = MustPublicKeyFromBase58("BPFLoaderUpgradeab1e11111111111111111111111") // Verify secp256k1 public key recovery operations (ecrecover). Secp256k1ProgramID = MustPublicKeyFromBase58("KeccakSecp256k11111111111111111111111111111") FeatureProgramID = MustPublicKeyFromBase58("Feature111111111111111111111111111111111111") ComputeBudget = MustPublicKeyFromBase58("ComputeBudget111111111111111111111111111111") // Create and manage address lookup tables. AddressLookupTableProgramID = MustPublicKeyFromBase58("AddressLookupTab1e1111111111111111111111111") )
var ( // A Token program on the Solana blockchain. // This program defines a common implementation for Fungible and Non Fungible tokens. TokenProgramID = MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") Token2022ProgramID = MustPublicKeyFromBase58("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb") // A Uniswap-like exchange for the Token program on the Solana blockchain, // implementing multiple automated market maker (AMM) curves. TokenSwapProgramID = MustPublicKeyFromBase58("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8") TokenSwapFeeOwner = MustPublicKeyFromBase58("HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN") // A lending protocol for the Token program on the Solana blockchain inspired by Aave and Compound. TokenLendingProgramID = MustPublicKeyFromBase58("LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi") // This program defines the convention and provides the mechanism for mapping // the user's wallet address to the associated token accounts they hold. SPLAssociatedTokenAccountProgramID = MustPublicKeyFromBase58("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL") // The Memo program is a simple program that validates a string of UTF-8 encoded characters // and verifies that any accounts provided are signers of the transaction. // The program also logs the memo, as well as any verified signer addresses, // to the transaction log, so that anyone can easily observe memos // and know they were approved by zero or more addresses // by inspecting the transaction log from a trusted provider. MemoProgramID = MustPublicKeyFromBase58("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr") // MemoProgramIDV1 is the deprecated v1 Memo program. // Some legacy transactions still reference this program ID. MemoProgramIDV1 = MustPublicKeyFromBase58("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo") )
SPL:
var ( SolMint = MustPublicKeyFromBase58("So11111111111111111111111111111111111111111") WrappedSol = MustPublicKeyFromBase58("So11111111111111111111111111111111111111112") )
var ( // Owner address for sysvar accounts. SysVarPubkey = MustPublicKeyFromBase58("Sysvar1111111111111111111111111111111111111") // The Clock sysvar contains data on cluster time, // including the current slot, epoch, and estimated wall-clock Unix timestamp. // It is updated every slot. SysVarClockPubkey = MustPublicKeyFromBase58("SysvarC1ock11111111111111111111111111111111") // The EpochRewards sysvar contains epoch rewards distribution data. SysVarEpochRewardsPubkey = MustPublicKeyFromBase58("SysvarEpochRewards1111111111111111111111111") // The EpochSchedule sysvar contains epoch scheduling constants that are set in genesis, // and enables calculating the number of slots in a given epoch, // the epoch for a given slot, etc. // (Note: the epoch schedule is distinct from the leader schedule) SysVarEpochSchedulePubkey = MustPublicKeyFromBase58("SysvarEpochSchedu1e111111111111111111111111") // The Fees sysvar contains the fee calculator for the current slot. // It is updated every slot, based on the fee-rate governor. SysVarFeesPubkey = MustPublicKeyFromBase58("SysvarFees111111111111111111111111111111111") // The Instructions sysvar contains the serialized instructions in a Message while that Message is being processed. // This allows program instructions to reference other instructions in the same transaction. SysVarInstructionsPubkey = MustPublicKeyFromBase58("Sysvar1nstructions1111111111111111111111111") // The LastRestartSlot sysvar contains the last restart slot. SysVarLastRestartSlotPubkey = MustPublicKeyFromBase58("SysvarLastRestartS1ot1111111111111111111111") // The RecentBlockhashes sysvar contains the active recent blockhashes as well as their associated fee calculators. // It is updated every slot. // Entries are ordered by descending block height, // so the first entry holds the most recent block hash, // and the last entry holds an old block hash. SysVarRecentBlockHashesPubkey = MustPublicKeyFromBase58("SysvarRecentB1ockHashes11111111111111111111") // The Rent sysvar contains the rental rate. // Currently, the rate is static and set in genesis. // The Rent burn percentage is modified by manual feature activation. SysVarRentPubkey = MustPublicKeyFromBase58("SysvarRent111111111111111111111111111111111") // The Rewards sysvar. SysVarRewardsPubkey = MustPublicKeyFromBase58("SysvarRewards111111111111111111111111111111") // The SlotHashes sysvar contains the most recent hashes of the slot's parent banks. // It is updated every slot. SysVarSlotHashesPubkey = MustPublicKeyFromBase58("SysvarS1otHashes111111111111111111111111111") // The SlotHistory sysvar contains a bitvector of slots present over the last epoch. It is updated every slot. SysVarSlotHistoryPubkey = MustPublicKeyFromBase58("SysvarS1otHistory11111111111111111111111111") // The StakeHistory sysvar contains the history of cluster-wide stake activations and de-activations per epoch. // It is updated at the start of every epoch. SysVarStakeHistoryPubkey = MustPublicKeyFromBase58("SysvarStakeHistory1111111111111111111111111") // The stake config account is used to store parameters and settings that govern the behavior of staking on the Solana network. SysVarStakeConfigPubkey = MustPublicKeyFromBase58("StakeConfig11111111111111111111111111111111") )
From https://github.com/anza-xyz/solana-sdk/blob/master/sdk-ids/src/lib.rs
var ErrAddressTablesNotSet = errors.New(
"address tables not set for versioned message with lookups; " +
"fetch each table id returned by Message.GetAddressTableLookups().GetTableIDs() " +
"(e.g. via rpc.Client.GetMultipleAccounts, decoding each account with " +
"addresslookuptable.DecodeAddressLookupTableState) " +
"and pass the resolved {tableID -> []PublicKey} map to Message.SetAddressTables",
)
ErrAddressTablesNotSet is returned by `(*Message).AccountMetaList`, `(*Message).ResolveLookups`, and friends when the message is a versioned (V0+) transaction with one or more address-table lookups but the actual table contents have not been provided yet via `(*Message).SetAddressTables`. Callers can use `errors.Is` to detect this specific condition (see #280) without scraping the error text.
var ErrAlreadyResolved = fmt.Errorf("lookups already resolved")
var ErrIllegalOwner = errors.New("provided owner is not allowed")
ErrIllegalOwner is returned by CreateWithSeed when the owner ends with the program-derived-address marker, which is disallowed.
var ErrInstructionDecoderNotFound = errors.New("instruction decoder not found")
var ErrMaxSeedLengthExceeded = errors.New("max seed length exceeded")
var ErrNonceUninitialized = errors.New("nonce account is uninitialized")
ErrNonceUninitialized is returned by Authorize when the nonce account has not been initialized.
var TokenMetadataProgramID = MustPublicKeyFromBase58("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
Functions ¶
func DecimalsInBigInt ¶
func DecodeInstruction ¶
func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, data []byte) (any, error)
func GetAddedRemovedPubkeys ¶ added in v1.1.0
func GetAddedRemovedPubkeys(previous PublicKeySlice, next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)
GetAddedRemovedPubkeys accepts two slices of pubkeys (`previous` and `next`), and returns two slices: - `added` is the slice of pubkeys that are present in `next` but NOT present in `previous`. - `removed` is the slice of pubkeys that are present in `previous` but are NOT present in `next`.
func IsAnyOfEncodingType ¶ added in v0.3.5
func IsAnyOfEncodingType(candidate EncodingType, allowed ...EncodingType) bool
IsAnyOfEncodingType checks whether the provided `candidate` is any of the `allowed`.
func IsSanitizeError ¶ added in v1.17.0
IsSanitizeError reports whether err is a sanitization validation error.
func LamportsPerSignatureOf ¶ added in v1.22.0
LamportsPerSignatureOf decodes a nonce account's data and returns the per-signature fee it records, or (0, false) when uninitialized or undecodable.
Mirrors nonce_account::lamports_per_signature_of, which likewise does NOT verify the account owner; this function only takes the data bytes and cannot. Pass data you have already confirmed belongs to a System-owned nonce account (e.g. via GetSystemAccountKind or VerifyNonceAccount), or treat the result as advisory.
func MustRegisterInstructionDecoder ¶ added in v1.17.0
func MustRegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)
MustRegisterInstructionDecoder is like RegisterInstructionDecoder but panics on error. Intended for use in init() functions where error handling is not possible.
func RegisterInstructionDecoder ¶
func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder) error
RegisterInstructionDecoder registers a decoder for the given programID. Returns an error if a different decoder is already registered for that programID. Re-registering the same decoder function is a no-op.
func ValidatePrivateKey ¶ added in v1.12.0
Types ¶
type Account ¶
type Account struct {
// Lamports in the account.
Lamports uint64 `json:"lamports"`
// Data held in this account.
Data []byte `json:"data"`
// Owner is the program that owns this account. If executable, the
// program that loads this account.
Owner PublicKey `json:"owner"`
// Executable indicates whether this account's data contains a loaded
// program (and is now read-only).
Executable bool `json:"executable"`
// RentEpoch is the epoch at which this account will next owe rent.
RentEpoch uint64 `json:"rentEpoch"`
}
Account is the on-chain state of an account: lamports, raw data, owner, executable flag, and rent epoch.
This is a port of the upstream anza-xyz/solana-sdk `account` crate's `Account` struct. It is the plain binary-state counterpart of rpc.Account (which is shaped for JSON-RPC responses): use this type when working with bincode-encoded account state, test fixtures, or off-chain tooling that mirrors validator-side types.
The bincode codec below matches the Rust serde encoding of solana_account::Account exactly (fields in declaration order, little-endian integers, Vec<u8> as u64 length + bytes).
The json tags are a plain debug/convenience form only; the resulting JSON is not compatible with the JSON-RPC shape of rpc.Account (in particular, Data encodes as base64 rather than the RPC data envelope).
NOTE: MarshalWithEncoder/UnmarshalWithDecoder are custom-codec hooks that every gagliardetto/binary encoder dispatches to, so a borsh or compact-u16 container with an Account field still emits the bincode layout for it. Likewise, embedding Account anonymously in another struct promotes these methods to the outer type, which would then (de)serialize only the Account fields; give such wrapper structs their own codec methods.
func DecodeAccount ¶ added in v1.23.0
DecodeAccount decodes a bincode-encoded solana_account::Account. Trailing bytes are tolerated; see UnmarshalBinary.
func (Account) MarshalBinary ¶ added in v1.23.0
MarshalBinary bincode-encodes the account, matching the Rust serde encoding of solana_account::Account.
func (Account) MarshalWithEncoder ¶ added in v1.23.0
func (*Account) UnmarshalBinary ¶ added in v1.23.0
UnmarshalBinary decodes a bincode-encoded account. Trailing bytes after the account are tolerated: Rust's bincode::deserialize free function is declared with allow_trailing_bytes(), and Agave decodes account state through it (e.g. Account::deserialize_data), so leniency IS the parity behavior.
type AccountMeta ¶
func Meta ¶ added in v0.4.0
func Meta( pubKey PublicKey, ) *AccountMeta
Meta intializes a new AccountMeta with the provided pubKey.
func NewAccountMeta ¶ added in v0.4.0
func NewAccountMeta( pubKey PublicKey, WRITE bool, SIGNER bool, ) *AccountMeta
func (*AccountMeta) SIGNER ¶ added in v0.4.0
func (meta *AccountMeta) SIGNER() *AccountMeta
SIGNER sets IsSigner to true.
func (*AccountMeta) WRITE ¶ added in v0.4.0
func (meta *AccountMeta) WRITE() *AccountMeta
WRITE sets IsWritable to true.
type AccountMetaSlice ¶ added in v0.4.0
type AccountMetaSlice []*AccountMeta
func (*AccountMetaSlice) Append ¶ added in v0.4.0
func (slice *AccountMetaSlice) Append(account *AccountMeta)
func (AccountMetaSlice) Get ¶ added in v1.1.0
func (slice AccountMetaSlice) Get(index int) *AccountMeta
Get returns the AccountMeta at the desired index. If the index is not present, it returns nil.
func (AccountMetaSlice) GetAccounts ¶ added in v0.4.0
func (slice AccountMetaSlice) GetAccounts() []*AccountMeta
func (AccountMetaSlice) GetKeys ¶ added in v1.2.0
func (slice AccountMetaSlice) GetKeys() PublicKeySlice
GetKeys returns the pubkeys of all AccountMeta.
func (AccountMetaSlice) GetSigners ¶ added in v0.4.0
func (slice AccountMetaSlice) GetSigners() []*AccountMeta
GetSigners returns the accounts that are signers.
func (AccountMetaSlice) Len ¶ added in v0.4.4
func (slice AccountMetaSlice) Len() int
func (*AccountMetaSlice) SetAccounts ¶ added in v0.4.0
func (slice *AccountMetaSlice) SetAccounts(accounts []*AccountMeta) error
func (AccountMetaSlice) SplitFrom ¶ added in v0.4.4
func (slice AccountMetaSlice) SplitFrom(index int) (AccountMetaSlice, AccountMetaSlice)
type AccountsGettable ¶ added in v0.4.0
type AccountsGettable interface {
GetAccounts() (accounts []*AccountMeta)
}
type AccountsSettable ¶ added in v0.4.0
type AccountsSettable interface {
SetAccounts(accounts []*AccountMeta) error
}
type Base64 ¶ added in v1.12.0
type Base64 []byte
func (Base64) MarshalJSON ¶ added in v1.12.0
func (*Base64) UnmarshalJSON ¶ added in v1.12.0
type ByteWrapper ¶
func (*ByteWrapper) ReadByte ¶
func (w *ByteWrapper) ReadByte() (byte, error)
type CompiledInstruction ¶
type CompiledInstruction struct {
// Index into the message.accountKeys array indicating the program account that executes this instruction.
// NOTE: it is actually a uint8, but using a uint16 because uint8 is treated as a byte everywhere,
// and that can be an issue.
ProgramIDIndex uint16 `json:"programIdIndex"`
// List of ordered indices into the message.accountKeys array indicating which accounts to pass to the program.
// NOTE: it is actually a []uint8, but using a uint16 because []uint8 is treated as a []byte everywhere,
// and that can be an issue.
Accounts []uint16 `json:"accounts"`
// The program input data encoded in a base-58 string.
Data Base58 `json:"data"`
}
func (*CompiledInstruction) ResolveInstructionAccounts ¶
func (ci *CompiledInstruction) ResolveInstructionAccounts(message *Message) ([]*AccountMeta, error)
type Data ¶
type Data struct {
Content []byte
Encoding EncodingType
}
func (Data) MarshalJSON ¶
func (Data) MarshalWithEncoder ¶ added in v1.2.0
func (*Data) UnmarshalJSON ¶
type DurableNonce ¶ added in v1.22.0
type DurableNonce Hash
DurableNonce is the 32-byte value stored in an initialized nonce account and used as the recent_blockhash field of a durable-nonce transaction.
Although it is used in the recent_blockhash slot, it is NOT a real blockhash: it is derived from one via DurableNonceFromBlockhash with a domain prefix.
func DurableNonceFromBlockhash ¶ added in v1.22.0
func DurableNonceFromBlockhash(blockhash Hash) DurableNonce
DurableNonceFromBlockhash derives a durable nonce from a blockhash, computing sha256("DURABLE_NONCE" || blockhash). Mirrors DurableNonce::from_blockhash.
func (DurableNonce) AsHash ¶ added in v1.22.0
func (d DurableNonce) AsHash() Hash
AsHash returns the durable nonce as a Hash, i.e. the value to place in a transaction's recent_blockhash field. Mirrors DurableNonce::as_hash.
func (DurableNonce) Equals ¶ added in v1.22.0
func (d DurableNonce) Equals(other DurableNonce) bool
Equals reports whether two durable nonces are equal.
func (DurableNonce) IsZero ¶ added in v1.22.0
func (d DurableNonce) IsZero() bool
IsZero reports whether the durable nonce is the zero value.
func (DurableNonce) String ¶ added in v1.22.0
func (d DurableNonce) String() string
type DurationMilliseconds ¶ added in v1.7.0
type DurationMilliseconds int64
DurationMilliseconds represents a duration in milliseconds.
func (DurationMilliseconds) Duration ¶ added in v1.7.0
func (res DurationMilliseconds) Duration() time.Duration
func (DurationMilliseconds) String ¶ added in v1.7.0
func (res DurationMilliseconds) String() string
type DurationSeconds ¶ added in v1.0.1
type DurationSeconds int64
DurationSeconds represents a duration in seconds.
func (DurationSeconds) Duration ¶ added in v1.0.1
func (res DurationSeconds) Duration() time.Duration
func (DurationSeconds) String ¶ added in v1.0.1
func (res DurationSeconds) String() string
type EncodingType ¶
type EncodingType string
const ( EncodingBase58 EncodingType = "base58" // limited to Account data of less than 129 bytes EncodingBase64 EncodingType = "base64" // will return base64 encoded data for Account data of any size EncodingBase64Zstd EncodingType = "base64+zstd" // compresses the Account data using Zstandard and base64-encodes the result // attempts to use program-specific state parsers to // return more human-readable and explicit account state data. // If "jsonParsed" is requested but a parser cannot be found, // the field falls back to "base64" encoding, detectable when the data field is type <string>. // Cannot be used if specifying dataSlice parameters (offset, length). EncodingJSONParsed EncodingType = "jsonParsed" EncodingJSON EncodingType = "json" // NOTE: you're probably looking for EncodingJSONParsed )
type Feature ¶ added in v1.23.0
type Feature struct {
// Slot at which the feature was activated; nil while pending.
ActivatedAt *uint64
}
Feature is the state of a feature-gate account (owner FeatureProgramID).
func DecodeFeature ¶ added in v1.23.0
DecodeFeature decodes a bincode-encoded Feature (Option<u64>).
func FeatureFromAccount ¶ added in v1.23.0
FeatureFromAccount decodes a Feature after checking the account owner, mirroring feature-gate-interface from_account.
func (Feature) MarshalWithEncoder ¶ added in v1.23.0
type FeatureSet ¶ added in v1.23.0
FeatureSet maps feature gate IDs to their activation slot, a minimal counterpart of the Rust FeatureSet's active map. The zero value (nil) is a valid, empty set.
func (FeatureSet) ActivatedSlot ¶ added in v1.23.0
func (fs FeatureSet) ActivatedSlot(id PublicKey) (uint64, bool)
ActivatedSlot returns the activation slot of the feature, if activated.
func (FeatureSet) IsActive ¶ added in v1.23.0
func (fs FeatureSet) IsActive(id PublicKey) bool
IsActive reports whether the feature is activated.
type FeeCalculator ¶ added in v1.22.0
type FeeCalculator struct {
LamportsPerSignature uint64
}
FeeCalculator records the cost, in lamports per signature, to process a transaction. Mirrors solana-sdk fee-calculator's FeeCalculator.
func (FeeCalculator) MarshalWithEncoder ¶ added in v1.22.0
func (obj FeeCalculator) MarshalWithEncoder(encoder *bin.Encoder) (err error)
func (*FeeCalculator) UnmarshalWithDecoder ¶ added in v1.22.0
func (obj *FeeCalculator) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
type GenericInstruction ¶ added in v0.5.0
type GenericInstruction struct {
AccountValues AccountMetaSlice
ProgID PublicKey
DataBytes []byte
}
func NewInstruction ¶ added in v0.5.0
func NewInstruction( programID PublicKey, accounts AccountMetaSlice, data []byte, ) *GenericInstruction
NewInstruction creates a generic instruction with the provided programID, accounts, and data bytes.
func (*GenericInstruction) Accounts ¶ added in v0.5.0
func (in *GenericInstruction) Accounts() []*AccountMeta
func (*GenericInstruction) Data ¶ added in v0.5.0
func (in *GenericInstruction) Data() ([]byte, error)
func (*GenericInstruction) ProgramID ¶ added in v0.5.0
func (in *GenericInstruction) ProgramID() PublicKey
type Hash ¶
type Hash PublicKey
func HashFromBase58 ¶
HashFromBase58 decodes a base58 string into a Hash.
func HashFromBytes ¶ added in v1.0.2
HashFromBytes decodes a byte slice into a Hash.
func MustHashFromBase58 ¶
MustHashFromBase58 decodes a base58 string into a Hash. Panics on error.
func (Hash) MarshalJSON ¶
func (Hash) MarshalText ¶ added in v1.6.0
MarshalText implements encoding.TextMarshaler.
func (*Hash) UnmarshalJSON ¶
func (*Hash) UnmarshalText ¶ added in v1.6.0
UnmarshalText implements encoding.TextUnmarshaler.
type Instruction ¶
type Instruction interface {
ProgramID() PublicKey // the programID the instruction acts on
Accounts() []*AccountMeta // returns the list of accounts the instructions requires
Data() ([]byte, error) // the binary encoded instructions
}
type InstructionDecoder ¶
type InstructionDecoder func(instructionAccounts []*AccountMeta, data []byte) (any, error)
InstructionDecoder receives the AccountMeta FOR THAT INSTRUCTION, and not the accounts of the *Message object. Resolve with CompiledInstruction.ResolveInstructionAccounts(message) beforehand.
type Message ¶
type Message struct {
// List of base-58 encoded public keys used by the transaction,
// including by the instructions and for signatures.
// The first `message.header.numRequiredSignatures` public keys must sign the transaction.
AccountKeys PublicKeySlice `json:"accountKeys"` // static keys; static keys + dynamic keys if after resolution (i.e. call to `ResolveLookups()`)
// Details the account types and signatures required by the transaction.
Header MessageHeader `json:"header"`
// A base-58 encoded hash of a recent block in the ledger used to
// prevent transaction duplication and to give transactions lifetimes.
RecentBlockhash Hash `json:"recentBlockhash"`
// List of program instructions that will be executed in sequence
// and committed in one atomic transaction if all succeed.
Instructions []CompiledInstruction `json:"instructions"`
// List of address table lookups used to load additional accounts for this transaction (v0 only).
AddressTableLookups MessageAddressTableLookupSlice `json:"addressTableLookups"`
// Inline compute budget (v1 only, SIMD-0385).
TransactionConfig TransactionConfig `json:"transactionConfig"`
// contains filtered or unexported fields
}
func (*Message) AccountMetaList ¶
func (m *Message) AccountMetaList() (AccountMetaSlice, error)
func (*Message) AddAddressTableLookup ¶ added in v1.7.0
func (mx *Message) AddAddressTableLookup(lookup MessageAddressTableLookup) *Message
AddAddressTableLookup adds a lookup; legacy becomes v0, v1 is kept.
func (*Message) EncodeToTree ¶ added in v0.4.0
func (*Message) GetAccountIndex ¶ added in v1.9.0
GetAccountIndex returns the index of the given account (first occurrence of the account).
func (*Message) GetAddressTableLookupAccounts ¶ added in v1.8.0
func (mx *Message) GetAddressTableLookupAccounts() (PublicKeySlice, error)
GetAddressTableLookupAccounts associates the lookups with the accounts in the actual address tables, and returns the accounts. NOTE: you need to call `SetAddressTables` before calling this method, so that the lookups can be associated with the accounts in the address tables.
func (*Message) GetAddressTableLookups ¶ added in v1.7.0
func (mx *Message) GetAddressTableLookups() MessageAddressTableLookupSlice
GetAddressTableLookups returns the lookups used by this message.
func (*Message) GetAddressTables ¶ added in v1.7.0
func (mx *Message) GetAddressTables() map[PublicKey]PublicKeySlice
GetAddressTables returns the actual address tables used by this message. NOTE: you must have called `SetAddressTable` before being able to use this method.
func (*Message) GetAllKeys ¶ added in v1.8.0
func (mx *Message) GetAllKeys() (keys PublicKeySlice, err error)
GetAllKeys returns ALL the message's account keys (including the keys from resolved address lookup tables).
func (*Message) GetIxSigners ¶ added in v1.18.0
func (m *Message) GetIxSigners(ixIndex int) PublicKeySlice
GetIxSigners returns the set of account keys that are both signers and referenced as accounts (not program) in the instruction at the given index.
func (*Message) GetVersion ¶ added in v1.7.0
func (m *Message) GetVersion() MessageVersion
GetVersion returns the message version.
func (*Message) HasAccount ¶ added in v1.2.0
func (*Message) HasDuplicates ¶ added in v1.17.0
HasDuplicates checks if the message has duplicate account keys. Uses O(n^2) comparison but requires no heap allocation, which is faster for the typically small number of accounts in a message. Ported from solana-sdk/message/legacy.rs has_duplicates().
func (*Message) IsInstructionAccount ¶ added in v1.18.0
IsInstructionAccount returns true if the given account index is referenced as an account (not a program) in any instruction.
func (*Message) IsResolved ¶ added in v1.11.0
func (*Message) IsVersioned ¶ added in v1.7.0
IsVersioned reports whether the message is v0 or v1 (not legacy).
func (*Message) IsWritableStatic ¶ added in v1.13.0
IsWritableStatic checks if the account is a writable account in the static accounts list, ignoring the accounts in the address table lookups.
func (*Message) MarshalBinary ¶ added in v0.3.5
func (Message) MarshalJSON ¶ added in v1.8.4
func (*Message) MarshalLegacy ¶ added in v1.7.0
func (*Message) MarshalV1 ¶ added in v1.23.0
MarshalV1 encodes the message as v1 (0x81 prefix included); never truncates.
func (Message) MarshalWithEncoder ¶ added in v0.4.0
func (*Message) NumLookups ¶ added in v1.8.0
func (*Message) NumReadonlyAccounts ¶ added in v1.18.0
NumReadonlyAccounts returns the total number of readonly accounts (signed + unsigned) in the static account list.
func (*Message) NumWritableLookups ¶ added in v1.8.0
func (*Message) ProgramIDs ¶ added in v1.18.0
func (m *Message) ProgramIDs() PublicKeySlice
ProgramIDs returns the deduplicated list of program IDs used by the message's instructions.
func (*Message) ProgramPosition ¶ added in v1.18.0
ProgramPosition returns the 0-based position of the account at the given index among all program IDs invoked by the message. Returns (pos, true) if found, or (0, false) if the account is not a program ID.
func (*Message) ResolveLookups ¶ added in v1.8.0
ResolveLookups resolves the address table lookups, and appends the resolved accounts to the `message.AccountKeys` field. NOTE: you need to call `SetAddressTables` before calling this method.
func (*Message) ResolveLookupsWith ¶ added in v1.13.0
func (mx *Message) ResolveLookupsWith(writable, readonly PublicKeySlice) (err error)
ResolveLookupsWith resolves the address table lookups with the provided writable and readonly accounts, assuming that the order of the accounts is correct.
func (*Message) ResolveProgramIDIndex ¶
ResolveProgramIDIndex resolves the program ID index to a program ID. DEPRECATED: use `Program(index)` instead.
func (*Message) Sanitize ¶ added in v1.17.0
Sanitize validates the structural integrity of a Message. Ported from solana-sdk/message legacy.rs, v0/mod.rs sanitize() and v1 validate().
func (*Message) SetAddressTableLookups ¶ added in v1.7.0
func (mx *Message) SetAddressTableLookups(lookups []MessageAddressTableLookup) *Message
SetAddressTableLookups (re)sets the lookups; legacy becomes v0, v1 is kept.
func (*Message) SetAddressTables ¶ added in v1.7.0
func (mx *Message) SetAddressTables(tables map[PublicKey]PublicKeySlice) error
SetAddressTables sets the actual address tables used by this message. Use `mx.GetAddressTableLookups().GetTableIDs()` to get the list of all address table IDs. NOTE: you can call this once.
func (*Message) SetVersion ¶ added in v1.7.0
func (m *Message) SetVersion(version MessageVersion) (*Message, error)
SetVersion forces the encoding version. V1 cannot carry lookups; leaving V1 with a non-empty config is an error.
func (*Message) Signers ¶ added in v1.2.0
func (m *Message) Signers() PublicKeySlice
Signers returns the pubkeys of all accounts that are signers.
func (*Message) UnmarshalBase64 ¶ added in v1.7.0
func (*Message) UnmarshalJSON ¶ added in v1.19.0
UnmarshalJSON decodes the message; `addressTableLookups` selects v0, `transactionConfig` v1.
func (*Message) UnmarshalLegacy ¶ added in v1.7.0
func (*Message) UnmarshalV0 ¶ added in v1.7.0
func (*Message) UnmarshalV1 ¶ added in v1.23.0
UnmarshalV1 decodes a v1 message from the 0x81 prefix; limits are checked by Sanitize.
func (*Message) UnmarshalWithDecoder ¶ added in v0.4.0
func (*Message) Writable ¶ added in v1.2.0
func (m *Message) Writable() (out PublicKeySlice, err error)
Writable returns the pubkeys of all accounts that are writable.
type MessageAddressTableLookup ¶ added in v1.7.0
type MessageAddressTableLookup struct {
AccountKey PublicKey `json:"accountKey"` // The account key of the address table.
WritableIndexes Uint8SliceAsNum `json:"writableIndexes"`
ReadonlyIndexes Uint8SliceAsNum `json:"readonlyIndexes"`
}
type MessageAddressTableLookupSlice ¶ added in v1.7.0
type MessageAddressTableLookupSlice []MessageAddressTableLookup
func (MessageAddressTableLookupSlice) GetTableIDs ¶ added in v1.7.0
func (lookups MessageAddressTableLookupSlice) GetTableIDs() PublicKeySlice
GetTableIDs returns the list of all address table IDs.
func (MessageAddressTableLookupSlice) NumLookups ¶ added in v1.7.0
func (lookups MessageAddressTableLookupSlice) NumLookups() int
NumLookups returns the number of accounts from all the lookups.
func (MessageAddressTableLookupSlice) NumWritableLookups ¶ added in v1.8.0
func (lookups MessageAddressTableLookupSlice) NumWritableLookups() int
NumWritableLookups returns the number of writable accounts across all the lookups (all the address tables).
type MessageHeader ¶
type MessageHeader struct {
// The total number of signatures required to make the transaction valid.
// The signatures must match the first `numRequiredSignatures` of `message.account_keys`.
NumRequiredSignatures uint8 `json:"numRequiredSignatures"`
// The last numReadonlySignedAccounts of the signed keys are read-only accounts.
// Programs may process multiple transactions that load read-only accounts within
// a single PoH entry, but are not permitted to credit or debit lamports or modify
// account data.
// Transactions targeting the same read-write account are evaluated sequentially.
NumReadonlySignedAccounts uint8 `json:"numReadonlySignedAccounts"`
// The last `numReadonlyUnsignedAccounts` of the unsigned keys are read-only accounts.
NumReadonlyUnsignedAccounts uint8 `json:"numReadonlyUnsignedAccounts"`
}
func (*MessageHeader) EncodeToTree ¶ added in v0.4.0
func (header *MessageHeader) EncodeToTree(mxBranch treeout.Branches)
type MessageVersion ¶ added in v1.7.0
type MessageVersion int
const ( MessageVersionLegacy MessageVersion = 0 // default MessageVersionV0 MessageVersion = 1 // v0 MessageVersionV1 MessageVersion = 2 // v1 (SIMD-0385) )
type MissingRequiredSignatureError ¶ added in v1.22.0
type MissingRequiredSignatureError struct {
// Authority is the nonce account's current authority whose signature is
// required.
Authority PublicKey
}
MissingRequiredSignatureError is returned by Authorize when the current nonce authority is not among the provided signers.
func (*MissingRequiredSignatureError) Error ¶ added in v1.22.0
func (e *MissingRequiredSignatureError) Error() string
type NonceData ¶ added in v1.22.0
type NonceData struct {
// Authority is the address allowed to sign transactions that consume and
// advance this nonce.
Authority PublicKey
// DurableNonce is the current nonce value.
DurableNonce DurableNonce
// FeeCalculator records the fee in effect when the nonce was last advanced.
FeeCalculator FeeCalculator
}
NonceData is the initialized data of a durable transaction nonce account.
func NewNonceData ¶ added in v1.22.0
func NewNonceData(authority PublicKey, durableNonce DurableNonce, lamportsPerSignature uint64) NonceData
NewNonceData builds nonce data from an authority, durable nonce and the lamports-per-signature fee. Mirrors Data::new.
func VerifyNonceAccount ¶ added in v1.22.0
VerifyNonceAccount decodes a system-owned nonce account and verifies that recentBlockhash matches its current nonce, returning the nonce data when valid. The account owner must be the System program. Mirrors nonce_account::verify_nonce_account.
func (NonceData) Blockhash ¶ added in v1.22.0
Blockhash returns the hash to use as a transaction's recent_blockhash when spending this nonce. Mirrors Data::blockhash.
func (NonceData) LamportsPerSignature ¶ added in v1.22.0
LamportsPerSignature returns the per-signature fee recorded for the next transaction that uses this nonce. Mirrors Data::get_lamports_per_signature.
func (NonceData) MarshalWithEncoder ¶ added in v1.22.0
type NonceState ¶ added in v1.22.0
type NonceState struct {
Kind NonceStateKind
// Data is meaningful only when Kind == NonceStateInitialized.
Data NonceData
}
NonceState is the state of a durable transaction nonce account: a discriminated union that is either Uninitialized or Initialized with NonceData.
func NewInitializedNonceState ¶ added in v1.22.0
func NewInitializedNonceState(authority PublicKey, durableNonce DurableNonce, lamportsPerSignature uint64) NonceState
NewInitializedNonceState builds an initialized nonce state. Mirrors State::new_initialized.
func (NonceState) IsInitialized ¶ added in v1.22.0
func (s NonceState) IsInitialized() bool
IsInitialized reports whether the nonce account has been initialized.
func (NonceState) MarshalWithEncoder ¶ added in v1.22.0
func (s NonceState) MarshalWithEncoder(encoder *bin.Encoder) (err error)
func (*NonceState) UnmarshalWithDecoder ¶ added in v1.22.0
func (s *NonceState) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
type NonceStateKind ¶ added in v1.22.0
type NonceStateKind uint32
NonceStateKind identifies whether a nonce account has been initialized.
const ( NonceStateUninitialized NonceStateKind = 0 NonceStateInitialized NonceStateKind = 1 )
type NonceVersion ¶ added in v1.22.0
type NonceVersion uint32
NonceVersion identifies the version of a nonce account's state. Only Current nonces have durable-nonce and blockhash domains separated and can therefore authorize durable-nonce transactions.
const ( NonceVersionLegacy NonceVersion = 0 NonceVersionCurrent NonceVersion = 1 )
type NonceVersions ¶ added in v1.22.0
type NonceVersions struct {
Version NonceVersion
State NonceState
}
NonceVersions wraps a NonceState together with its version. It is the type stored in a nonce account's data. Mirrors solana_nonce::versions::Versions.
func DecodeNonceVersions ¶ added in v1.22.0
func DecodeNonceVersions(data []byte) (*NonceVersions, error)
DecodeNonceVersions decodes a nonce account's data into NonceVersions. Any trailing bytes (e.g. the zero padding present because the account is allocated at NonceStateSize) are ignored. The account-verification helpers use decodeNonceVersionsStrict instead, to match upstream bincode semantics.
func NewNonceVersions ¶ added in v1.22.0
func NewNonceVersions(state NonceState) NonceVersions
NewNonceVersions wraps a state in a Current version. Mirrors Versions::new.
func (NonceVersions) Authorize ¶ added in v1.22.0
func (v NonceVersions) Authorize(signers []PublicKey, newAuthority PublicKey) (NonceVersions, error)
Authorize sets a new authority on the nonce account. The current authority must be present in signers. The version variant is preserved because the durable_nonce field is not changed here. Mirrors Versions::authorize.
func (NonceVersions) LamportsPerSignature ¶ added in v1.22.0
func (v NonceVersions) LamportsPerSignature() (uint64, bool)
LamportsPerSignature returns the per-signature fee of an initialized nonce, or (0, false) when uninitialized.
func (NonceVersions) MarshalAccountData ¶ added in v1.22.0
func (v NonceVersions) MarshalAccountData() ([]byte, error)
MarshalAccountData returns the on-chain account data for this nonce, zero- padded to NonceStateSize bytes the way the runtime allocates it.
func (NonceVersions) MarshalBinary ¶ added in v1.22.0
func (v NonceVersions) MarshalBinary() ([]byte, error)
MarshalBinary returns the bincode-serialized nonce versions (8 bytes when uninitialized, NonceStateSize bytes when initialized).
func (NonceVersions) MarshalWithEncoder ¶ added in v1.22.0
func (v NonceVersions) MarshalWithEncoder(encoder *bin.Encoder) (err error)
func (*NonceVersions) UnmarshalBinary ¶ added in v1.22.0
func (v *NonceVersions) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes nonce versions from bincode-serialized bytes, satisfying encoding.BinaryUnmarshaler as the counterpart to MarshalBinary. Like DecodeNonceVersions it tolerates trailing bytes (e.g. account padding).
func (*NonceVersions) UnmarshalWithDecoder ¶ added in v1.22.0
func (v *NonceVersions) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
func (NonceVersions) Upgrade ¶ added in v1.22.0
func (v NonceVersions) Upgrade() (NonceVersions, bool)
Upgrade migrates a Legacy nonce into the Current durable-nonce domain. It returns (_, false) when there is nothing to upgrade: the nonce is already Current, or it is an uninitialized Legacy nonce (which is upgraded on initialization instead). Mirrors Versions::upgrade.
func (NonceVersions) VerifyRecentBlockhash ¶ added in v1.22.0
func (v NonceVersions) VerifyRecentBlockhash(recentBlockhash Hash) (*NonceData, bool)
VerifyRecentBlockhash checks that recentBlockhash matches this nonce and returns the nonce data if so. Legacy versions never verify, because durable nonces in the legacy blockhash domain are invalid. Mirrors Versions::verify_recent_blockhash.
type PrivateKey ¶
type PrivateKey []byte
func MustPrivateKeyFromBase58 ¶
func MustPrivateKeyFromBase58(in string) PrivateKey
func NewRandomPrivateKey ¶
func NewRandomPrivateKey() (PrivateKey, error)
func PrivateKeyFromBase58 ¶
func PrivateKeyFromBase58(privkey string) (PrivateKey, error)
func PrivateKeyFromMnemonic ¶ added in v1.21.0
func PrivateKeyFromMnemonic(mnemonic, passphrase string) (PrivateKey, error)
PrivateKeyFromMnemonic derives a PrivateKey from a BIP-39 mnemonic using the default Solana derivation path (m/44'/501'/0'/0'). The passphrase may be empty; when set, it must match the passphrase used when the mnemonic was generated.
func PrivateKeyFromMnemonicAtPath ¶ added in v1.21.0
func PrivateKeyFromMnemonicAtPath(mnemonic, passphrase, path string) (PrivateKey, error)
PrivateKeyFromMnemonicAtPath derives a PrivateKey from a BIP-39 mnemonic at the given SLIP-0010 derivation path. All path segments must be hardened (suffixed with ' or h); SLIP-0010 does not define non-hardened derivation for ed25519.
func PrivateKeyFromSeedAtPath ¶ added in v1.21.0
func PrivateKeyFromSeedAtPath(seed []byte, path string) (PrivateKey, error)
PrivateKeyFromSeedAtPath derives a PrivateKey from a 16..64 byte seed (typically a 64 byte BIP-39 seed) using the given SLIP-0010 derivation path. All path segments must be hardened.
func PrivateKeyFromSolanaKeygenFile ¶
func PrivateKeyFromSolanaKeygenFile(file string) (PrivateKey, error)
func PrivateKeyFromSolanaKeygenFileBytes ¶ added in v1.12.0
func PrivateKeyFromSolanaKeygenFileBytes(content []byte) (PrivateKey, error)
func (PrivateKey) IsValid ¶ added in v1.12.0
func (k PrivateKey) IsValid() bool
IsValid returns whether the private key is valid.
func (PrivateKey) PublicKey ¶
func (k PrivateKey) PublicKey() PublicKey
func (PrivateKey) String ¶
func (k PrivateKey) String() string
func (PrivateKey) Validate ¶ added in v1.12.0
func (k PrivateKey) Validate() error
type PublicKey ¶
type PublicKey [PublicKeyLength]byte
func CreateProgramAddress ¶ added in v0.4.0
Create a program address. Ported from https://github.com/solana-labs/solana/blob/216983c50e0a618facc39aa07472ba6d23f1b33a/sdk/program/src/pubkey.rs#L204
func CreateWithSeed ¶ added in v0.4.0
func FindAssociatedTokenAddress ¶ added in v0.4.0
func FindAssociatedTokenAddressWithProgram ¶ added in v1.17.0
func FindAssociatedTokenAddressWithProgram( wallet PublicKey, mint PublicKey, tokenProgram PublicKey, ) (PublicKey, uint8, error)
FindAssociatedTokenAddressWithProgram returns the associated token account PDA for the provided wallet, mint, and token program.
func FindProgramAddress ¶ added in v0.4.0
Find a valid program address and its corresponding bump seed.
func FindTokenMetadataAddress ¶ added in v1.0.2
FindTokenMetadataAddress returns the token metadata program-derived address given a SPL token mint address.
func GetAssociatedAuthority ¶ added in v1.12.0
Get the marketAuthority(PDA) from the Market Initialization
func MustPublicKeyFromBase58 ¶
func PublicKeyFromBase58 ¶
PublicKeyFromBase58 creates a PublicKey from a base58 encoded string. NOTE: it will accept on- and off-curve pubkeys.
func PublicKeyFromBytes ¶
PublicKeyFromBytes creates a PublicKey from a byte slice that must be 32 bytes long. NOTE: it will accept on- and off-curve pubkeys.
func (PublicKey) IsAnyOf ¶ added in v1.8.0
IsAnyOf checks if p is equals to any of the provided keys.
func (PublicKey) IsZero ¶
IsZero returns whether the public key is zero. NOTE: the System Program public key is also zero.
func (PublicKey) MarshalBSON ¶ added in v1.8.2
MarshalBSON implements the bson.Marshaler interface.
func (PublicKey) MarshalBSONValue ¶ added in v1.8.2
MarshalBSONValue implements the bson.ValueMarshaler interface.
func (PublicKey) MarshalJSON ¶
func (PublicKey) MarshalText ¶ added in v0.3.4
func (PublicKey) Short ¶ added in v1.1.0
Short returns a shortened pubkey string, only including the first n chars, ellipsis, and the last n characters. NOTE: this is ONLY for visual representation for humans, and cannot be used for anything else.
func (*PublicKey) UnmarshalBSON ¶ added in v1.8.2
UnmarshalBSON implements the bson.Unmarshaler interface.
func (*PublicKey) UnmarshalBSONValue ¶ added in v1.8.2
UnmarshalBSONValue implements the bson.ValueUnmarshaler interface.
func (*PublicKey) UnmarshalJSON ¶
func (*PublicKey) UnmarshalText ¶ added in v0.3.4
type PublicKeySlice ¶ added in v0.4.0
type PublicKeySlice []PublicKey
func (PublicKeySlice) Added ¶ added in v1.7.0
func (a PublicKeySlice) Added(b PublicKeySlice) PublicKeySlice
Added returns the elements that are present in `b` but not in `a`.
func (*PublicKeySlice) Append ¶ added in v0.4.0
func (slice *PublicKeySlice) Append(pubkeys ...PublicKey)
func (PublicKeySlice) Contains ¶ added in v1.7.0
func (slice PublicKeySlice) Contains(pubkey PublicKey) bool
Contains returns true if the slice contains the provided pubkey.
func (PublicKeySlice) ContainsAll ¶ added in v1.7.0
func (slice PublicKeySlice) ContainsAll(pubkeys PublicKeySlice) bool
ContainsAll returns true if all the provided pubkeys are present in the slice.
func (PublicKeySlice) ContainsAny ¶ added in v1.7.0
func (slice PublicKeySlice) ContainsAny(pubkeys ...PublicKey) bool
ContainsAny returns true if any of the provided pubkeys are present in the slice.
func (PublicKeySlice) Dedupe ¶ added in v1.7.0
func (slice PublicKeySlice) Dedupe() PublicKeySlice
Dedupe returns a new slice with all duplicate pubkeys removed.
func (PublicKeySlice) Equals ¶ added in v1.7.0
func (slice PublicKeySlice) Equals(other PublicKeySlice) bool
Equals returns true if the two PublicKeySlices are equal (same order of same keys).
func (PublicKeySlice) First ¶ added in v1.7.0
func (slice PublicKeySlice) First() *PublicKey
First returns the first element of the slice. Returns nil if the slice is empty.
func (PublicKeySlice) GetAddedRemoved ¶ added in v1.7.0
func (prev PublicKeySlice) GetAddedRemoved(next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)
GetAddedRemoved compares to the `next` pubkey slice, and returns two slices: - `added` is the slice of pubkeys that are present in `next` but NOT present in `previous`. - `removed` is the slice of pubkeys that are present in `previous` but are NOT present in `next`.
func (PublicKeySlice) Has ¶ added in v0.4.0
func (slice PublicKeySlice) Has(pubkey PublicKey) bool
func (PublicKeySlice) Intersect ¶ added in v1.7.0
func (prev PublicKeySlice) Intersect(next PublicKeySlice) PublicKeySlice
Intersect returns the intersection of two PublicKeySlices, i.e. the elements that are in both PublicKeySlices. The returned PublicKeySlice is sorted and deduped.
func (PublicKeySlice) Last ¶ added in v1.7.0
func (slice PublicKeySlice) Last() *PublicKey
Last returns the last element of the slice. Returns nil if the slice is empty.
func (PublicKeySlice) Len ¶ added in v1.7.0
func (slice PublicKeySlice) Len() int
func (PublicKeySlice) Less ¶ added in v1.7.0
func (slice PublicKeySlice) Less(i, j int) bool
func (PublicKeySlice) Removed ¶ added in v1.7.0
func (a PublicKeySlice) Removed(b PublicKeySlice) PublicKeySlice
Removed returns the elements that are present in `a` but not in `b`.
func (PublicKeySlice) Same ¶ added in v1.7.0
func (slice PublicKeySlice) Same(other PublicKeySlice) bool
Same returns true if the two slices contain the same public keys, but not necessarily in the same order.
func (PublicKeySlice) Sort ¶ added in v1.7.0
func (slice PublicKeySlice) Sort()
Sort sorts the slice.
func (PublicKeySlice) Split ¶ added in v1.1.0
func (slice PublicKeySlice) Split(chunkSize int) []PublicKeySlice
Split splits the slice into chunks of the specified size.
func (PublicKeySlice) Swap ¶ added in v1.7.0
func (slice PublicKeySlice) Swap(i, j int)
func (PublicKeySlice) ToBase58 ¶ added in v1.7.0
func (slice PublicKeySlice) ToBase58() []string
func (PublicKeySlice) ToBytes ¶ added in v1.7.0
func (slice PublicKeySlice) ToBytes() [][]byte
func (PublicKeySlice) ToPointers ¶ added in v1.7.0
func (slice PublicKeySlice) ToPointers() []*PublicKey
func (*PublicKeySlice) UniqueAppend ¶ added in v0.4.0
func (slice *PublicKeySlice) UniqueAppend(pubkey PublicKey) bool
UniqueAppend appends the provided pubkey only if it is not already present in the slice. Returns true when the provided pubkey wasn't already present.
type Signature ¶
type Signature [64]byte
func MustSignatureFromBase58 ¶
MustSignatureFromBase58 decodes a base58 string into a Signature. Panics on error.
func SignatureFromBase58 ¶
SignatureFromBase58 decodes a base58 string into a Signature.
func SignatureFromBytes ¶ added in v1.2.0
SignatureFromBytes decodes a byte slice into a Signature.
func (Signature) MarshalJSON ¶
func (Signature) MarshalText ¶ added in v1.6.0
func (*Signature) UnmarshalJSON ¶
func (*Signature) UnmarshalText ¶ added in v1.6.0
type SystemAccountKind ¶ added in v1.22.0
type SystemAccountKind int
SystemAccountKind classifies a system-program-owned account.
const ( SystemAccountKindSystem SystemAccountKind = iota SystemAccountKindNonce )
func GetSystemAccountKind ¶ added in v1.22.0
func GetSystemAccountKind(owner PublicKey, data []byte) (SystemAccountKind, bool)
GetSystemAccountKind classifies a system-program-owned account as a plain system account or an initialized nonce account, returning (_, false) for any other account (wrong owner, or data that is neither empty nor a valid initialized nonce). Mirrors nonce_account::get_system_account_kind.
type Transaction ¶
type Transaction struct {
// A list of base-58 encoded signatures applied to the transaction.
// The list is always of length `message.header.numRequiredSignatures` and not empty.
// The signature at index `i` corresponds to the public key at index
// `i` in `message.account_keys`. The first one is used as the transaction id.
// Wire: legacy/v0 = compact-u16 count + sigs + message; v1 = message + sigs.
Signatures []Signature `json:"signatures"`
// Defines the content of the transaction.
Message Message `json:"message"`
}
func MustTransactionFromDecoder ¶ added in v0.4.1
func MustTransactionFromDecoder(decoder *bin.Decoder) *Transaction
MustTransactionFromDecoder decodes a transaction from a decoder. Panics on error.
func NewTransaction ¶
func NewTransaction(instructions []Instruction, recentBlockHash Hash, opts ...TransactionOption) (*Transaction, error)
Example (V1) ¶
ExampleNewTransaction_v1 builds, signs, serializes and decodes a V1 (SIMD-0385) transaction with an inline compute budget configuration.
package main
import (
"crypto/ed25519"
"fmt"
"github.com/gagliardetto/solana-go"
)
func main() {
// Deterministic keys for the example; use solana.NewWallet() in real code.
payerKey := solana.PrivateKey(ed25519.NewKeyFromSeed(make([]byte, 32)))
payer := payerKey.PublicKey()
recipient := solana.MustPublicKeyFromBase58("2mHtsPqiHkQKKh6t2Q1jGwYQ8vG7ULfF7c9k4t9BvGkw")
programID := solana.SystemProgramID
// Any Instruction works; this is a raw System Program transfer of 1 lamport.
data := []byte{2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}
ix := solana.NewInstruction(programID, solana.AccountMetaSlice{
solana.Meta(payer).WRITE().SIGNER(),
solana.Meta(recipient).WRITE(),
}, data)
// A zero blockhash for the example; fetch it from the RPC in real code.
var blockhash solana.Hash
tx, err := solana.NewTransaction(
[]solana.Instruction{ix},
blockhash,
solana.TransactionPayer(payer),
// Selects v1; unset CU limit means 0, PriorityFee is total lamports.
solana.TransactionV1Config(solana.TransactionConfig{}.
WithComputeUnitLimit(20_000).
WithPriorityFee(1_000)),
)
if err != nil {
panic(err)
}
if _, err := tx.Sign(func(key solana.PublicKey) *solana.PrivateKey {
if key.Equals(payer) {
return &payerKey
}
return nil
}); err != nil {
panic(err)
}
// Wire: 0x81 prefix first, signatures last (no length prefix).
wire, err := tx.MarshalBinary()
if err != nil {
panic(err)
}
decoded, err := solana.TransactionFromBytes(wire)
if err != nil {
panic(err)
}
fmt.Println("version:", decoded.Message.GetVersion() == solana.MessageVersionV1)
fmt.Println("prefix: 0x" + fmt.Sprintf("%02x", wire[0]))
fmt.Println("compute unit limit:", *decoded.Message.TransactionConfig.ComputeUnitLimit)
fmt.Println("priority fee:", *decoded.Message.TransactionConfig.PriorityFee)
fmt.Println("heap size requested:", decoded.Message.TransactionConfig.HeapSize != nil)
fmt.Println("size ok:", len(wire) <= solana.MaxTransactionSizeV1)
fmt.Println("signatures valid:", decoded.VerifySignatures() == nil)
}
Output: version: true prefix: 0x81 compute unit limit: 20000 priority fee: 1000 heap size requested: false size ok: true signatures valid: true
func TransactionFromBase58 ¶ added in v1.11.0
func TransactionFromBase58(b58 string) (*Transaction, error)
func TransactionFromBase64 ¶ added in v1.11.0
func TransactionFromBase64(b64 string) (*Transaction, error)
func TransactionFromBytes ¶ added in v1.11.0
func TransactionFromBytes(data []byte) (*Transaction, error)
TransactionFromBytes decodes a transaction from the whole slice. For v1, trailing bytes are rejected (SIMD-0385); legacy/v0 stay lenient. Streaming callers can use TransactionFromDecoder, which is always lenient.
func TransactionFromDecoder ¶ added in v0.4.0
func TransactionFromDecoder(decoder *bin.Decoder) (*Transaction, error)
TransactionFromDecoder decodes a transaction from a decoder.
func (*Transaction) AccountMetaList ¶
func (t *Transaction) AccountMetaList() ([]*AccountMeta, error)
func (*Transaction) EncodeToTree ¶ added in v0.4.0
func (tx *Transaction) EncodeToTree(parent treeout.Branches)
func (*Transaction) EncodeTree ¶ added in v0.4.0
func (tx *Transaction) EncodeTree(encoder *text.TreeEncoder) (int, error)
func (*Transaction) GetAccountIndex ¶ added in v1.9.0
func (t *Transaction) GetAccountIndex(account PublicKey) (uint16, error)
func (*Transaction) GetNonceAccount ¶ added in v1.17.0
func (tx *Transaction) GetNonceAccount() (PublicKey, bool)
GetNonceAccount returns the public key of the nonce account if this transaction uses a durable nonce. The nonce account is the first account of the first instruction (the AdvanceNonceAccount instruction). Returns the zero PublicKey and false if this is not a nonce transaction.
func (*Transaction) GetProgramIDs ¶ added in v1.11.0
func (tx *Transaction) GetProgramIDs() (PublicKeySlice, error)
func (*Transaction) HasAccount ¶ added in v1.2.0
func (t *Transaction) HasAccount(account PublicKey) (bool, error)
func (*Transaction) IsSigner ¶
func (t *Transaction) IsSigner(account PublicKey) bool
func (*Transaction) IsVote ¶ added in v1.13.0
func (tx *Transaction) IsVote() bool
func (*Transaction) IsWritable ¶
func (t *Transaction) IsWritable(account PublicKey) (bool, error)
func (*Transaction) MarshalBinary ¶ added in v0.3.5
func (tx *Transaction) MarshalBinary() ([]byte, error)
func (Transaction) MarshalWithEncoder ¶ added in v0.4.0
func (tx Transaction) MarshalWithEncoder(encoder *bin.Encoder) error
func (Transaction) MustToBase64 ¶ added in v1.3.0
func (tx Transaction) MustToBase64() string
func (*Transaction) NumReadonlyAccounts ¶ added in v1.11.0
func (tx *Transaction) NumReadonlyAccounts() int
func (*Transaction) NumSigners ¶ added in v1.11.0
func (tx *Transaction) NumSigners() int
func (*Transaction) NumWriteableAccounts ¶ added in v1.11.0
func (tx *Transaction) NumWriteableAccounts() int
func (*Transaction) PartialSign ¶ added in v1.7.0
func (tx *Transaction) PartialSign(getter privateKeyGetter) (out []Signature, err error)
func (*Transaction) ResolveProgramIDIndex ¶
func (t *Transaction) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)
func (*Transaction) Sanitize ¶ added in v1.17.0
func (tx *Transaction) Sanitize() error
Sanitize validates the structural integrity of a Transaction. It checks that the signature count matches the message header and that the message itself is valid. Ported from solana-sdk/transaction: lib.rs and versioned/mod.rs sanitize().
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(getter privateKeyGetter) (out []Signature, err error)
func (*Transaction) String ¶ added in v1.2.0
func (tx *Transaction) String() string
String returns a human-readable string representation of the transaction data. To disable colors, set "github.com/gagliardetto/solana-go/text".DisableColors = true
func (Transaction) ToBase64 ¶ added in v1.3.0
func (tx Transaction) ToBase64() (string, error)
func (*Transaction) UnmarshalBase64 ¶ added in v1.7.0
func (tx *Transaction) UnmarshalBase64(b64 string) error
UnmarshalBase64 decodes a base64 encoded transaction.
func (*Transaction) UnmarshalWithDecoder ¶ added in v0.4.0
func (tx *Transaction) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
func (*Transaction) UsesDurableNonce ¶ added in v1.17.0
func (tx *Transaction) UsesDurableNonce() bool
UsesDurableNonce checks whether this transaction uses a durable nonce by inspecting the first instruction. Returns true if the first instruction is a System Program AdvanceNonceAccount instruction. Ported from solana-sdk/transaction: uses_durable_nonce().
func (*Transaction) VerifySignatures ¶ added in v1.2.0
func (tx *Transaction) VerifySignatures() error
VerifySignatures verifies all the signatures in the transaction against the pubkeys of the signers.
func (*Transaction) VerifyWithResults ¶ added in v1.17.0
func (tx *Transaction) VerifyWithResults() ([]bool, error)
VerifyWithResults verifies each signature independently and returns a per-signature boolean result. Ported from solana-sdk/transaction/lib.rs verify_with_results().
type TransactionBuilder ¶ added in v0.4.0
type TransactionBuilder struct {
// contains filtered or unexported fields
}
func NewTransactionBuilder ¶ added in v0.4.0
func NewTransactionBuilder() *TransactionBuilder
NewTransactionBuilder creates a new instruction builder.
func (*TransactionBuilder) AddInstruction ¶ added in v0.4.0
func (builder *TransactionBuilder) AddInstruction(instruction Instruction) *TransactionBuilder
AddInstruction adds the provided instruction to the builder.
func (*TransactionBuilder) Build ¶ added in v0.4.0
func (builder *TransactionBuilder) Build() (*Transaction, error)
Build builds and returns a *Transaction.
func (*TransactionBuilder) SetFeePayer ¶ added in v0.4.0
func (builder *TransactionBuilder) SetFeePayer(feePayer PublicKey) *TransactionBuilder
Set transaction fee payer. If not set, defaults to first signer account of the first instruction.
func (*TransactionBuilder) SetRecentBlockHash ¶ added in v0.4.0
func (builder *TransactionBuilder) SetRecentBlockHash(recentBlockHash Hash) *TransactionBuilder
SetRecentBlockHash sets the recent blockhash for the instruction builder.
func (*TransactionBuilder) SetTransactionConfig ¶ added in v1.23.0
func (builder *TransactionBuilder) SetTransactionConfig(config TransactionConfig) *TransactionBuilder
SetTransactionConfig sets the v1 inline compute budget (see TransactionV1Config).
func (*TransactionBuilder) SetVersion ¶ added in v1.23.0
func (builder *TransactionBuilder) SetVersion(version MessageVersion) *TransactionBuilder
SetVersion selects the message version (see TransactionMessageVersion).
func (*TransactionBuilder) WithOpt ¶ added in v0.4.0
func (builder *TransactionBuilder) WithOpt(opt TransactionOption) *TransactionBuilder
WithOpt adds a TransactionOption.
type TransactionConfig ¶ added in v1.23.0
type TransactionConfig struct {
// Total priority fee in lamports.
PriorityFee *uint64 `json:"priorityFee"`
// Maximum compute units; nil means 0.
ComputeUnitLimit *uint32 `json:"computeUnitLimit"`
// Maximum bytes of loaded account data; nil means 0.
LoadedAccountsDataSizeLimit *uint32 `json:"loadedAccountsDataSizeLimit"`
// Heap size: multiple of 1024 in [MinHeapSizeV1, MaxHeapSizeV1]; nil means default.
HeapSize *uint32 `json:"heapSize"`
}
TransactionConfig is the v1 inline compute budget; nil field = not requested. Unset ComputeUnitLimit means 0 CUs; PriorityFee is total lamports.
func (*TransactionConfig) EncodeToTree ¶ added in v1.23.0
func (c *TransactionConfig) EncodeToTree(branch treeout.Branches)
EncodeToTree renders the config; unset fields are shown as "<unset>".
func (TransactionConfig) IsEmpty ¶ added in v1.23.0
func (c TransactionConfig) IsEmpty() bool
IsEmpty reports whether no config value is set.
func (TransactionConfig) Mask ¶ added in v1.23.0
func (c TransactionConfig) Mask() TransactionConfigMask
Mask returns the TransactionConfigMask describing which values are set.
func (TransactionConfig) Size ¶ added in v1.23.0
func (c TransactionConfig) Size() int
Size returns the encoded size of the config values in bytes.
func (TransactionConfig) WithComputeUnitLimit ¶ added in v1.23.0
func (c TransactionConfig) WithComputeUnitLimit(units uint32) TransactionConfig
WithComputeUnitLimit returns a copy with the compute unit limit set.
func (TransactionConfig) WithHeapSize ¶ added in v1.23.0
func (c TransactionConfig) WithHeapSize(bytes uint32) TransactionConfig
WithHeapSize returns a copy with the heap size set (validated by Sanitize).
func (TransactionConfig) WithLoadedAccountsDataSizeLimit ¶ added in v1.23.0
func (c TransactionConfig) WithLoadedAccountsDataSizeLimit(bytes uint32) TransactionConfig
WithLoadedAccountsDataSizeLimit returns a copy with the loaded accounts data size limit set.
func (TransactionConfig) WithPriorityFee ¶ added in v1.23.0
func (c TransactionConfig) WithPriorityFee(lamports uint64) TransactionConfig
WithPriorityFee returns a copy with the priority fee (total lamports) set.
type TransactionConfigMask ¶ added in v1.23.0
type TransactionConfigMask uint32
TransactionConfigMask flags which config values a V1 message carries.
const ( // TransactionConfigMaskPriorityFee: bits 0-1 (both required), u64 LE. TransactionConfigMaskPriorityFee TransactionConfigMask = 0b11 // TransactionConfigMaskComputeUnitLimit: bit 2, u32 LE. TransactionConfigMaskComputeUnitLimit TransactionConfigMask = 0b100 // TransactionConfigMaskLoadedAccountsDataSize: bit 3, u32 LE. TransactionConfigMaskLoadedAccountsDataSize TransactionConfigMask = 0b1000 // TransactionConfigMaskHeapSize: bit 4, u32 LE. TransactionConfigMaskHeapSize TransactionConfigMask = 0b10000 // TransactionConfigMaskKnownBits is the union of all supported bits. TransactionConfigMaskKnownBits = TransactionConfigMaskPriorityFee | TransactionConfigMaskComputeUnitLimit | TransactionConfigMaskLoadedAccountsDataSize | TransactionConfigMaskHeapSize )
func (TransactionConfigMask) HasComputeUnitLimit ¶ added in v1.23.0
func (m TransactionConfigMask) HasComputeUnitLimit() bool
HasComputeUnitLimit reports whether the compute unit limit bit is set.
func (TransactionConfigMask) HasHeapSize ¶ added in v1.23.0
func (m TransactionConfigMask) HasHeapSize() bool
HasHeapSize reports whether the heap size bit is set.
func (TransactionConfigMask) HasInvalidPriorityFeeBits ¶ added in v1.23.0
func (m TransactionConfigMask) HasInvalidPriorityFeeBits() bool
HasInvalidPriorityFeeBits reports whether exactly one priority fee bit is set.
func (TransactionConfigMask) HasLoadedAccountsDataSize ¶ added in v1.23.0
func (m TransactionConfigMask) HasLoadedAccountsDataSize() bool
HasLoadedAccountsDataSize reports whether the loaded accounts data size bit is set.
func (TransactionConfigMask) HasPriorityFee ¶ added in v1.23.0
func (m TransactionConfigMask) HasPriorityFee() bool
HasPriorityFee reports whether both priority fee bits are set.
func (TransactionConfigMask) HasUnknownBits ¶ added in v1.23.0
func (m TransactionConfigMask) HasUnknownBits() bool
HasUnknownBits reports whether any unsupported bit is set.
func (TransactionConfigMask) SizeOfConfig ¶ added in v1.23.0
func (m TransactionConfigMask) SizeOfConfig() int
SizeOfConfig returns the encoded size of the flagged config values.
type TransactionOption ¶
type TransactionOption interface {
// contains filtered or unexported methods
}
func TransactionAddressTables ¶ added in v1.8.0
func TransactionAddressTables(tables map[PublicKey]PublicKeySlice) TransactionOption
func TransactionMessageVersion ¶ added in v1.23.0
func TransactionMessageVersion(version MessageVersion) TransactionOption
TransactionMessageVersion selects the message version built by NewTransaction. V1 rejects address tables and ComputeBudget instructions; prefer TransactionV1Config.
func TransactionPayer ¶
func TransactionPayer(payer PublicKey) TransactionOption
func TransactionV1Config ¶ added in v1.23.0
func TransactionV1Config(config TransactionConfig) TransactionOption
TransactionV1Config sets the v1 inline compute budget and implies MessageVersionV1.
type Uint8SliceAsNum ¶ added in v1.8.4
type Uint8SliceAsNum []uint8
Uint8SliceAsNum is a slice of uint8s that can be marshaled as numbers instead of a byte slice.
func (Uint8SliceAsNum) MarshalJSON ¶ added in v1.8.4
func (slice Uint8SliceAsNum) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
type UnixTimeMilliseconds ¶ added in v1.5.0
type UnixTimeMilliseconds int64
UnixTimeMilliseconds represents a UNIX millisecond-resolution timestamp.
func (UnixTimeMilliseconds) String ¶ added in v1.5.0
func (res UnixTimeMilliseconds) String() string
func (UnixTimeMilliseconds) Time ¶ added in v1.5.0
func (res UnixTimeMilliseconds) Time() time.Time
type UnixTimeSeconds ¶ added in v0.5.0
type UnixTimeSeconds int64
UnixTimeSeconds represents a UNIX second-resolution timestamp.
func (UnixTimeSeconds) String ¶ added in v0.5.1
func (res UnixTimeSeconds) String() string
func (UnixTimeSeconds) Time ¶ added in v0.5.0
func (res UnixTimeSeconds) Time() time.Time
type Wallet ¶ added in v0.4.2
type Wallet struct {
PrivateKey PrivateKey
}
Wallet is a wrapper around a PrivateKey
func NewWalletFromMnemonic ¶ added in v1.21.0
NewWalletFromMnemonic creates a Wallet whose private key is derived from a BIP-39 mnemonic using the default Solana derivation path m/44'/501'/0'/0'.
func WalletFromPrivateKeyBase58 ¶ added in v0.4.2
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bip39 is the Golang implementation of the BIP39 spec.
|
Package bip39 is the Golang implementation of the BIP39 spec. |
|
cmd
|
|
|
slnc
command
|
|
|
programs
|
|
|
compute-budget
Package computebudget provides the ComputeBudget program instructions.
|
Package computebudget provides the ComputeBudget program instructions. |
|
token-2022/zkencryption
Package zkencryption ports the deterministic key-derivation functions from solana-zk-sdk (zk-sdk/src/encryption) to Go.
|
Package zkencryption ports the deterministic key-derivation functions from solana-zk-sdk (zk-sdk/src/encryption) to Go. |
|
token-2022/zkencryption/examples/deriveKeys
command
Command deriveKeys shows how to deterministically derive the two key materials used by the Token-2022 confidential-transfer extension from a Solana signer: the ElGamal secret key and the AES (AeKey) key.
|
Command deriveKeys shows how to deterministically derive the two key materials used by the Token-2022 confidential-transfer extension from a Solana signer: the ElGamal secret key and the AES (AeKey) key. |
|
examples/createMint
command
createMint builds and submits the two-instruction transaction that creates a new SPL Token mint on devnet:
|
createMint builds and submits the two-instruction transaction that creates a new SPL Token mint on devnet: |
|
examples/getAccountInfo
command
|
|
|
examples/getBalance
command
|
|
|
examples/getBlock
command
|
|
|
examples/getBlockCommitment
command
|
|
|
examples/getBlockHeight
command
|
|
|
examples/getBlockProduction
command
|
|
|
examples/getBlockTime
command
|
|
|
examples/getBlocks
command
|
|
|
examples/getBlocksWithLimit
command
|
|
|
examples/getClusterNodes
command
|
|
|
examples/getEpochInfo
command
|
|
|
examples/getEpochSchedule
command
|
|
|
examples/getFeeForMessage
command
|
|
|
examples/getFirstAvailableBlock
command
|
|
|
examples/getGenesisHash
command
|
|
|
examples/getHealth
command
|
|
|
examples/getHighestSnapshotSlot
command
|
|
|
examples/getIdentity
command
|
|
|
examples/getInflationGovernor
command
|
|
|
examples/getInflationRate
command
|
|
|
examples/getInflationReward
command
|
|
|
examples/getLargestAccounts
command
|
|
|
examples/getLatestBlockhash
command
|
|
|
examples/getLeaderSchedule
command
|
|
|
examples/getMaxRetransmitSlot
command
|
|
|
examples/getMaxShredInsertSlot
command
|
|
|
examples/getMultipleAccounts
command
|
|
|
examples/getProgramAccounts
command
|
|
|
examples/getSignatureStatuses
command
|
|
|
examples/getSignaturesForAddress
command
|
|
|
examples/getSlot
command
|
|
|
examples/getSlotLeader
command
|
|
|
examples/getSlotLeaders
command
|
|
|
examples/getSupply
command
|
|
|
examples/getTokenAccountBalance
command
|
|
|
examples/getTokenAccountsByOwner
command
|
|
|
examples/getTokenLargestAccounts
command
|
|
|
examples/getTokenSupply
command
|
|
|
examples/getTransaction
command
|
|
|
examples/getTransactionCount
command
|
|
|
examples/getVersion
command
|
|
|
examples/getVoteAccounts
command
|
|
|
examples/isBlockhashValid
command
|
|
|
examples/minimumLedgerSlot
command
|
|
|
examples/requestAirdrop
command
|
|
|
examples/sendEncodedTransaction
command
|
|
|
examples/sendRawTransaction
command
|
|
|
examples/sendTransaction
command
|
|
|
examples/sendTransactionV1
command
|
|
|
examples/simulateTransaction
command
|
|
|
jsonrpc
Package jsonrpc provides a JSON-RPC 2.0 client that sends JSON-RPC requests and receives JSON-RPC responses using HTTP.
|
Package jsonrpc provides a JSON-RPC 2.0 client that sends JSON-RPC requests and receives JSON-RPC responses using HTTP. |
|
ws/examples/accountSubscribe
command
|
|
|
ws/examples/logsSubscribe
command
|
|
|
ws/examples/programSubscribe
command
|
|
|
ws/examples/rootSubscribe
command
|
|
|
ws/examples/signatureSubscribe
command
|
|
|
ws/examples/slotSubscribe
command
|
|
|
ws/examples/voteSubscribe
command
|
|
