package
0.0.0-20250213232608-c453f8b35c75
Repository: https://github.com/stellar/go.git
Documentation: pkg.go.dev

# README

horizonclient

horizonclient is a Stellar Go SDK package that provides client access to a horizon server. It supports all endpoints exposed by the horizon API.

This project is maintained by the Stellar Development Foundation.

Getting Started

This library is aimed at developers building Go applications that interact with the Stellar network. It allows users to query the network and submit transactions to the network. The recommended transaction builder for Go programmers is txnbuild. Together, these two libraries provide a complete Stellar SDK.

Prerequisites

  • Go (this repository is officially supported on the last two releases of Go)
  • Modules to manage dependencies

Installing

  • go get github.com/stellar/go/clients/horizonclient

Usage

    ...
    import hClient "github.com/stellar/go/clients/horizonclient"
    ...

    // Use the default pubnet client
    client := hClient.DefaultPublicNetClient

    // Create an account request
    accountRequest := hClient.AccountRequest{AccountID: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

    // Load the account detail from the network
    account, err := client.AccountDetail(accountRequest)
    if err != nil {
        fmt.Println(err)
        return
    }
    // Account contains information about the stellar account
    fmt.Print(account)

For more examples, refer to the documentation.

Running the tests

Run the unit tests from the package directory: go test

Contributing

Please read Code of Conduct to understand this project's communication rules.

To submit improvements and fixes to this library, please see CONTRIBUTING.

License

This project is licensed under the Apache License - see the LICENSE file for details.

# Functions

GetError returns an error that can be interpreted as a horizon-specific error.
IsNotFoundError returns true if the error is a horizonclient.Error with a not_found problem indicating that the resource is not found on Horizon.
port - the horizon admin port, zero value defaults to 4200 host - the host interface name that horizon has bound admin web service, zero value defaults to 'localhost' timeout - the length of time for the http client to wait on responses from admin web service.

# Constants

AssetType12 represents an asset type that is 12 characters long.
AssetType4 represents an asset type that is 4 characters long.
AssetTypeNative represents the asset type for Stellar Lumens (XLM).
OrderAsc represents an ascending order parameter.
OrderDesc represents an descending order parameter.

# Variables

DayResolution represents 1 day used as `resolution` parameter in trade aggregation.
DefaultPublicNetClient is a default client to connect to public network.
DefaultTestNetClient is a default client to connect to test network.
ErrAccountRequiresMemo is the error returned from a call to checkMemoRequired when any of the destination accounts required a memo in the transaction.
ErrEnvelopeNotPopulated is the error returned from a call to Envelope() against a `Problem` value that doesn't have the "envelope_xdr" extra field populated when it is expected to be.
ErrResultCodesNotPopulated is the error returned from a call to ResultCodes() against a `Problem` value that doesn't have the "result_codes" extra field populated when it is expected to be.
ErrResultNotPopulated is the error returned from a call to Result() against a `Problem` value that doesn't have the "result_xdr" extra field populated when it is expected to be.
FifteenMinuteResolution represents 15 minutes used as `resolution` parameter in trade aggregation.
FiveMinuteResolution represents 5 minutes used as `resolution` parameter in trade aggregation.
HorizonTimeout is the default number of nanoseconds before a request to horizon times out.
HourResolution represents 1 hour used as `resolution` parameter in trade aggregation.
MinuteResolution represents 1 minute used as `resolution` parameter in trade aggregation.
ServerTimeMap holds the ServerTimeRecord for different horizon instances.
WeekResolution represents 1 week used as `resolution` parameter in trade aggregation.

# Structs

AccountRequest struct contains data for making requests to the show account endpoint of a horizon server.
AccountsRequest struct contains data for making requests to the accounts endpoint of a horizon server.
AssetRequest struct contains data for getting asset details from a horizon server.
ClaimableBalanceRequest contains data about claimable balances.
Client struct contains data for creating a horizon client that connects to the stellar network.
EffectRequest struct contains data for getting effects from a horizon server.
Error struct contains the problem returned by Horizon.
LedgerRequest struct contains data for getting ledger details from a horizon server.
LiquidityPoolRequest struct contains data for getting liquidity pool details from a horizon server.
LiquidityPoolsRequest struct contains data for getting pool details from a horizon server.
MockClient is a mockable horizon client.
OfferRequest struct contains data for getting offers made by an account from a horizon server.
OperationRequest struct contains data for getting operation details from a horizon server.
OrderBookRequest struct contains data for getting the orderbook for an asset pair from a horizon server.
PathsRequest struct contains data for getting available strict receive path payments from a horizon server.
ServerTimeRecord contains data for the current unix time of a horizon server instance, and the local time when it was recorded.
StrictSendPathsRequest struct contains data for getting available strict send path payments from a horizon server.
SubmitTxOpts represents the submit transaction options.
TradeAggregationRequest struct contains data for getting trade aggregations from a horizon server.
TradeRequest struct contains data for getting trade details from a horizon server.
TransactionRequest struct contains data for getting transaction details from a horizon server.

# Interfaces

ClientInterface contains methods implemented by the horizon client.
HorizonRequest contains methods implemented by request structs for horizon endpoints.
HTTP represents the HTTP client that a horizon client uses to communicate.

# Type aliases

AssetType represents `asset_type` param in queries.
EffectHandler is a function that is called when a new effect is received.
LedgerHandler is a function that is called when a new ledger is received.
OfferHandler is a function that is called when a new offer is received.
OperationHandler is a function that is called when a new operation is received.
Order represents `order` param in queries.
OrderBookHandler is a function that is called when a new order summary is received.
TradeHandler is a function that is called when a new trade is received.
TransactionHandler is a function that is called when a new transaction is received.
UniversalTimeHandler is a function that is called to return the UTC unix time in seconds.