HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulesolana-haskell-sdk-1.3.0.0GHC2021

Network.Solana.SolanaWeb3

Convenience layer on top of the JSON-RPC bindings: build, sign, and submit a transaction in one call, print account balances, and pause execution while waiting for confirmation. Intended for scripts and demos; for finer control over blockhash selection, error handling, and confirmation strategy use Network.Solana.Core.Message and Network.Solana.RPC.HTTP.Transaction directly.

Also bundles typed fetch helpers (getTokenAccount, getMint, getLookupTable, getStakeAccount, getNonceAccount, getMetadataAccount) that fetch an account over RPC and decode its state with the corresponding on-chain-state decoder, so callers don't have to extract and decode AccountData by hand. Like every other helper in this module, they require a reachable RPC node, so the unit suite only compiles them; live coverage comes from the opt-in local-validator integration suite (cabal test integration-tests --flags=integration, see the README), which exercises most but not all of them.

  • 18 values

Builds, signs, and submits a transaction that executes the given instructions, returning its signature.

Fetches the latest blockhash from the cluster, compiles the instructions with newTransactionIntentWithPayer naming the first key as the fee payer (forced into account 0 as a writable signer, even if no instruction marks it writable -- e.g. a memo-only or SPL authority-only transaction -- or references it at all), signs with the given keys (any order; signatures are placed in message order automatically), and broadcasts the result with sendTransaction.

Throws userError "newTransaction: no signers given" if the key list is empty, and a CompileException if an instruction references an account key that cannot be resolved in the compiled message, if a required signer has no corresponding key, or if a given key signs nothing.

Builds, signs, and submits a durable-nonce transaction with an explicitly named fee payer that executes the given instructions, returning its signature.

Reads the given nonce account at confirmed commitment to avoid stale-nonce races (a nonce account fetched at the node's default finalized commitment may appear not-found or stale immediately after creation or after being advanced), then builds the transaction with newDurableNonceTransactionIntentWithPayer, which prepends the nonce-advance instruction ahead of the given instructions and uses the nonce account's durable nonce in place of a recent block hash (so the transaction never expires, unlike newTransaction), and submits it with sendTransaction' under cfgNonceSendConfirmed, so the node's preflight simulation runs at that same confirmed commitment instead of its default finalized bank (which may not yet contain the nonce value used, or the account at all, immediately after creation or an advance). The fee payer is always account 0 (sponsored fees are supported), and the given signers may be listed in any order — they must include private keys corresponding to both the payer and the nonce account's authority (nsAuthority), or the resulting transaction will be rejected on submission. Requires a reachable RPC node.

Throws userError "newNonceTransaction: nonce account not found" if the account does not exist, and userError "newNonceTransaction: nonce account not initialized" if it exists but has not been initialized as a nonce account -- distinct from each other and from the CompileException thrown if an instruction references an account key that cannot be resolved in the compiled message.

Estimates a priority fee (in micro-lamports per compute unit) for landing a transaction that writes to the given accounts, as the p-th percentile of recent per-compute-unit fees observed for them (via getRecentPrioritizationFees and percentilePriorityFee).

Heuristic only: recent fees are no guarantee of what is needed to land the next transaction. Returns 0 if no recent priority fees were observed for the given accounts. Requires a reachable RPC node.

valuewait :: Int -> Web3 ()
#

Suspends execution for the given number of seconds, printing a notice first. A crude way to wait for transaction confirmation; prefer polling getSignatureStatuses in real applications.

Polls getSignatureStatuses once a second, up to 30 times, until the given signature reaches confirmed or finalized status.

Returns True only if the status reaches the target commitment and the node reports no on-chain error for it (its err field is Nothing); a transaction that landed but failed on-chain (e.g. a program error) yields False, not True. Also returns False if it does not confirm within the poll budget. See confirmFinalized to wait for finalization instead.

Polls getSignatureStatuses once a second, up to 60 times, until the given signature reaches finalized status.

Throws a userError if the transaction finalizes with an on-chain error, or if it does not finalize within the poll budget (naming the signature in both cases). Use it before reading state through helpers that use the node's default commitment (printBalances, getBalance, getTokenAccount, ...): a transaction that confirmTransaction reports at confirmed is not yet visible there.

Account-state fetch helpers

8 declarations

Fetches the given account with getAccountInfo and decodes its data with the given decoder, prefixing any failure message with the given label.

Returns Nothing if the account does not exist. Propagates the underlying JSON-RPC exception on RPC failure, same as every other RPC-backed helper in this module. Throws userError (label <> ": state decode failed: " <> err) if the account exists but its data cannot be decoded -- distinct from the not-found case.

Fetches the given address lookup table account, decodes it with decodeLookupTable, and bridges it into the AddressLookupTableAccount shape compileV0Message expects (via lookupTableToAccount), using the queried address as the table's own key.

Returns Nothing if the account does not exist. Throws on RPC failure, per fetchAccountState. Throws userError ("getLookupTable: state decode failed: " <> err) if the account exists but is not a well-formed lookup table -- distinct from the not-found case.

Fetches the Metaplex metadata account for the given mint (deriving its PDA with deriveMetadataAddress) and decodes it with decodeMetadata.

Calls error if the metadata PDA cannot be derived, matching the precedent set by createMetadataAccountV3 (practically unreachable: requires every bump candidate to land on-curve). Otherwise, returns Nothing if the metadata account does not exist. Throws on RPC failure, per fetchAccountState. Throws userError ("getMetadataAccount: state decode failed: " <> err) if the account exists but is not well-formed metadata -- distinct from the not-found case.