The node package is a JSON-RPC 2.0 client for the Mintlayer node daemon.
import "github.com/mintlayer/go-sdk/node"
c := node.New("http://127.0.0.1:3030",
node.WithBasicAuth("user", "pass"), // optional
node.WithTimeout(10*time.Second), // optional
)Default ports: 3030 (mainnet), 13030 (testnet).
Errors returned by the daemon are wrapped as *node.RPCError:
type RPCError struct {
Code int
Message string
}func (c *Client) ChainstateInfo(ctx context.Context) (*ChainstateInfo, error)Returns a summary of the current chain state.
type ChainstateInfo struct {
BestBlockHeight uint64 `json:"best_block_height"`
BestBlockID string `json:"best_block_id"`
BestBlockTimestamp Timestamp `json:"best_block_timestamp"`
MedianTime Timestamp `json:"median_time"`
IsInitialBlockDownload bool `json:"is_initial_block_download"`
}func (c *Client) BestBlockID(ctx context.Context) (string, error)Returns the hex block ID of the current tip.
func (c *Client) BestBlockHeight(ctx context.Context) (uint64, error)Returns the height of the current tip.
func (c *Client) BlockIDAtHeight(ctx context.Context, height uint64) (*string, error)Returns the block ID at a given height, or nil if no block exists at that height.
func (c *Client) BlockHeightInMainChain(ctx context.Context, blockID string) (*uint64, error)Returns the mainchain height for a block ID, or nil if the block is not on the main chain.
func (c *Client) GetBlock(ctx context.Context, id string) (*string, error)Returns the hex-encoded raw block.
func (c *Client) GetBlockJSON(ctx context.Context, id string) (json.RawMessage, error)Returns the block as a JSON object. Useful for inspection without custom deserialization.
func (c *Client) GetMainchainBlocks(ctx context.Context, from uint64, maxCount uint32) ([]string, error)Returns up to maxCount hex-encoded blocks starting at height from.
func (c *Client) GetUTXO(ctx context.Context, outpoint Outpoint) (json.RawMessage, error)Returns the output at a given outpoint as raw JSON.
type Outpoint struct {
SourceID OutpointSourceID `json:"source_id"`
Index uint32 `json:"index"`
}
type OutpointSourceID struct {
Type string `json:"type"` // "Transaction" or "BlockReward"
Content json.RawMessage `json:"content"` // {"tx_id":"hex"} or {"block_id":"hex"}
}func (c *Client) SubmitBlock(ctx context.Context, blockHex string) errorSubmits a hex-encoded block. Used by block producers.
func (c *Client) StakePoolBalance(ctx context.Context, poolAddress string) (*Amount, error)Returns the total balance of a pool (staker pledge plus all delegations). Returns nil if the pool is not found.
func (c *Client) StakerBalance(ctx context.Context, poolAddress string) (*Amount, error)Returns the staker's own balance, excluding delegations. Returns nil if the pool is not found.
func (c *Client) PoolDecommissionDestination(ctx context.Context, poolAddress string) (*string, error)Returns the address that receives funds when the pool is decommissioned.
func (c *Client) DelegationShare(ctx context.Context, poolAddress, delegationAddress string) (*Amount, error)Returns the amount owned by a specific delegation in a pool.
func (c *Client) TokenInfo(ctx context.Context, tokenID string) (*TokenInfo, error)Returns on-chain token metadata.
type TokenInfo struct {
Type string `json:"type"`
Content json.RawMessage `json:"content"`
}func (c *Client) TokensInfo(ctx context.Context, tokenIDs []string) ([]TokenInfo, error)Batch version of TokenInfo. More efficient than calling TokenInfo in a loop.
func (c *Client) OrderInfo(ctx context.Context, orderID string) (*OrderInfo, error)Returns the current state of an order.
type OrderInfo struct {
ConcludeKey string `json:"conclude_key"`
InitiallyAsked Amount `json:"initially_asked"`
InitiallyGiven Amount `json:"initially_given"`
AskBalance Amount `json:"ask_balance"`
GiveBalance Amount `json:"give_balance"`
Nonce uint64 `json:"nonce"`
IsFrozen bool `json:"is_frozen"`
}func (c *Client) OrdersInfoByCurrencies(ctx context.Context, ask, give *Currency) (map[string]OrderInfo, error)Returns all orders matching the given currency pair. Returns a map from order ID to OrderInfo. Pass nil for either currency to match any.
type Currency struct {
Type string `json:"type"` // "Coin" or "Token"
Content json.RawMessage `json:"content"` // {"token_id":"..."} when Type is "Token"
}func (c *Client) ContainsTx(ctx context.Context, txID string) (bool, error)Returns true if the mempool contains the transaction.
func (c *Client) ContainsOrphanTx(ctx context.Context, txID string) (bool, error)Returns true if the orphan pool contains the transaction.
func (c *Client) GetTransaction(ctx context.Context, txID string) (*MempoolTx, error)Returns a mempool transaction.
type MempoolTx struct {
ID string `json:"id"`
Status string `json:"status"`
Transaction json.RawMessage `json:"transaction"`
}func (c *Client) MempoolSubmitTransaction(ctx context.Context, txHex string, trustPolicy TrustPolicy) errorSubmits a transaction to the local mempool only, without broadcasting to peers. Use TrustPolicyTrusted for transactions you constructed yourself; use TrustPolicyUntrusted for externally sourced transactions.
func (c *Client) GetFeeRate(ctx context.Context, inTopXMb uint32) (*FeeRate, error)Returns the fee rate needed to land in the top inTopXMb megabytes of the mempool.
type FeeRate struct {
AmountPerKB Amount `json:"amount_per_kb"`
}func (c *Client) GetFeeRatePoints(ctx context.Context) ([]FeeRatePoint, error)Returns the mempool fee-rate curve as a slice of (size, rate) pairs.
func (c *Client) MemoryUsage(ctx context.Context) (uint64, error)Returns the current mempool memory usage in bytes.
func (c *Client) GetPeerCount(ctx context.Context) (uint64, error)Returns the number of currently connected peers.
func (c *Client) GetConnectedPeers(ctx context.Context) ([]PeerInfo, error)Returns details about all connected peers.
type PeerInfo struct {
PeerID uint64 `json:"peer_id"`
Address string `json:"address"`
PeerRole string `json:"peer_role"`
BanScore uint32 `json:"ban_score"`
UserAgent string `json:"user_agent"`
SoftwareVersion string `json:"software_version"`
PingWait *uint64 `json:"ping_wait"`
PingLast *uint64 `json:"ping_last"`
PingMin *uint64 `json:"ping_min"`
LastTipBlockTime *int64 `json:"last_tip_block_time"`
}func (c *Client) GetBindAddresses(ctx context.Context) ([]string, error)Returns the addresses the node is listening on for P2P connections.
func (c *Client) AddReservedNode(ctx context.Context, addr string) errorAdds a persistent peer that the node always attempts to reconnect to.
func (c *Client) RemoveReservedNode(ctx context.Context, addr string) errorRemoves a persistent peer.
func (c *Client) Connect(ctx context.Context, addr string) errorMakes a one-time connection attempt to a peer address.
func (c *Client) Disconnect(ctx context.Context, peerID uint64) errorCloses the connection to a peer by ID.
func (c *Client) ListBanned(ctx context.Context) ([]BannedPeer, error)Returns the list of banned peers.
type BannedPeer struct {
Address string `json:"address"`
BanTime Timestamp `json:"ban_time"`
}func (c *Client) Ban(ctx context.Context, address string, duration time.Duration) errorBans a peer for the specified duration.
func (c *Client) Unban(ctx context.Context, address string) errorRemoves a peer from the ban list.
func (c *Client) P2PSubmitTransaction(ctx context.Context, txHex string, trustPolicy TrustPolicy) errorSubmits a transaction to the mempool and broadcasts it to peers. This is the normal path for publishing a transaction to the network.
func (c *Client) NodeVersion(ctx context.Context) (string, error)Returns the node software version string.
func (c *Client) NodeShutdown(ctx context.Context) errorInitiates a graceful node shutdown.