Convert Figma logo to code with AI

stellar logogo

Stellar's public monorepo of go code

1,289
502
1,289
406

Top Related Projects

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin

⟁ Tendermint Core (BFT Consensus) in Go

:chains: A Framework for Building High Value Public Blockchains :sparkles:

libp2p implementation in Go

Go implementation of the Ethereum protocol

15,649

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.

Quick Overview

Stellar/go is the official Go implementation of the Stellar network protocol. It provides a comprehensive set of tools and libraries for interacting with the Stellar blockchain, including a full Stellar Core node implementation, Horizon API server, and various command-line tools for developers and network operators.

Pros

  • Robust and well-maintained implementation of the Stellar protocol
  • Extensive documentation and community support
  • High performance and scalability for handling Stellar network operations
  • Modular architecture allowing for easy integration and customization

Cons

  • Steep learning curve for developers new to blockchain technology
  • Requires significant resources to run a full Stellar Core node
  • Limited support for some advanced features compared to other blockchain platforms
  • Dependency on the Stellar network's overall health and stability

Code Examples

  1. Creating a new account:
import "github.com/stellar/go/clients/horizonclient"
import "github.com/stellar/go/keypair"

// Generate a new random keypair
pair, err := keypair.Random()
if err != nil {
    log.Fatal(err)
}

// Fund the account using friendbot (testnet only)
client := horizonclient.DefaultTestNetClient
resp, err := client.Fund(pair.Address())
if err != nil {
    log.Fatal(err)
}
  1. Sending a payment:
import "github.com/stellar/go/txnbuild"

// Create a payment operation
payment := txnbuild.Payment{
    Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
    Amount:      "10",
    Asset:       txnbuild.NativeAsset{},
}

// Build and submit the transaction
tx, err := txnbuild.NewTransaction(
    txnbuild.TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []txnbuild.Operation{&payment},
        BaseFee:              txnbuild.MinBaseFee,
        Timebounds:           txnbuild.NewTimeout(300),
    },
)
  1. Querying account information:
import "github.com/stellar/go/clients/horizonclient"

client := horizonclient.DefaultPublicNetClient
accountRequest := horizonclient.AccountRequest{AccountID: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"}
account, err := client.AccountDetail(accountRequest)
if err != nil {
    log.Fatal(err)
}
fmt.Println("Balance:", account.Balances[0].Balance)

Getting Started

To start using the Stellar Go SDK:

  1. Install Go (version 1.16 or later)
  2. Install the Stellar Go SDK:
    go get github.com/stellar/go
    
  3. Import the required packages in your Go code:
    import (
        "github.com/stellar/go/clients/horizonclient"
        "github.com/stellar/go/keypair"
        "github.com/stellar/go/txnbuild"
    )
    
  4. Initialize a Horizon client:
    client := horizonclient.DefaultTestNetClient
    

Now you're ready to interact with the Stellar network using the Go SDK!

Competitor Comparisons

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin

Pros of protoactor-go

  • Focused on actor-based concurrency, providing a robust framework for distributed systems
  • Offers high performance and scalability for concurrent applications
  • Supports multiple programming languages, enabling cross-language actor systems

Cons of protoactor-go

  • Narrower scope compared to stellar/go, which offers a broader range of blockchain-related functionalities
  • Less mature ecosystem and community support than stellar/go
  • Steeper learning curve for developers not familiar with the actor model

Code Comparison

protoactor-go:

type MyActor struct{}

func (state *MyActor) Receive(context actor.Context) {
    switch msg := context.Message().(type) {
    case string:
        fmt.Println("Received:", msg)
    }
}

stellar/go:

kp := keypair.MustParse("SDQVDISRYN2JXBS7ICL7QJAEKB3HWBJFP2QECXG7GZICAHBK4UNJCWK2")
client := horizonclient.DefaultTestNetClient
accountRequest := horizonclient.AccountRequest{AccountID: kp.Address()}
account, err := client.AccountDetail(accountRequest)

The code snippets demonstrate the different focus areas of each project. protoactor-go emphasizes actor-based message handling, while stellar/go provides blockchain-specific functionality for interacting with the Stellar network.

⟁ Tendermint Core (BFT Consensus) in Go

Pros of Tendermint

  • More flexible consensus mechanism, supporting various blockchain applications
  • Better performance and scalability for high-throughput applications
  • More active development community with frequent updates

Cons of Tendermint

  • Steeper learning curve for developers new to blockchain technology
  • Less focus on financial applications compared to Stellar
  • Potentially higher resource requirements for node operators

Code Comparison

Stellar (Go):

type Transaction struct {
    SourceAccount        AccountId
    Fee                  uint32
    SeqNum               SequenceNumber
    TimeBounds           *TimeBounds
    Memo                 Memo
    Operations           []Operation
    ExtraSigners         []SignerKey
}

Tendermint:

type Block struct {
    Header      Header
    Data        Data
    Evidence    EvidenceData
    LastCommit  *Commit
}

Key Differences

  • Stellar focuses on financial applications and has a simpler architecture
  • Tendermint offers more flexibility for various blockchain use cases
  • Stellar has a larger ecosystem of financial institutions and partners
  • Tendermint provides better support for custom blockchain development

Conclusion

Both projects have their strengths, with Stellar excelling in financial applications and Tendermint offering more flexibility for custom blockchain development. The choice between them depends on the specific requirements of your project and your team's expertise in blockchain technology.

:chains: A Framework for Building High Value Public Blockchains :sparkles:

Pros of Cosmos SDK

  • More extensive modular architecture, allowing for greater customization and flexibility in blockchain development
  • Stronger focus on interoperability between different blockchains through the Inter-Blockchain Communication (IBC) protocol
  • Larger and more active community, resulting in frequent updates and improvements

Cons of Cosmos SDK

  • Steeper learning curve due to its more complex architecture and broader scope
  • Higher resource requirements for running a full node compared to Stellar
  • Less emphasis on simplicity and ease of use for developers new to blockchain technology

Code Comparison

Cosmos SDK (account creation):

acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
app.AccountKeeper.SetAccount(ctx, acc)

Stellar (account creation):

account := hcnet.Account{
    Address: address,
    Sequence: 0,
}

Both repositories use Go as their primary language, but Cosmos SDK tends to have more complex code structures due to its modular design. Stellar's codebase is generally more straightforward and focused on specific use cases within the Stellar network.

libp2p implementation in Go

Pros of go-libp2p

  • More versatile and general-purpose networking library
  • Larger community and wider adoption across various projects
  • Extensive documentation and examples for easier implementation

Cons of go-libp2p

  • Steeper learning curve due to its broader scope
  • May include unnecessary features for simpler projects
  • Potentially higher resource usage for basic networking tasks

Code Comparison

go-libp2p:

host, err := libp2p.New(
    libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"),
    libp2p.Identity(priv),
)

stellar/go:

client := horizonclient.DefaultPublicNetClient
accountRequest := horizonclient.AccountRequest{AccountID: "ACCOUNT_ID"}
account, err := client.AccountDetail(accountRequest)

The go-libp2p example shows creating a host with custom options, while the stellar/go example demonstrates interacting with the Stellar network using a client. go-libp2p focuses on low-level networking, whereas stellar/go provides higher-level abstractions for Stellar-specific operations.

Both libraries serve different purposes: go-libp2p is a general-purpose peer-to-peer networking library, while stellar/go is specifically designed for interacting with the Stellar blockchain. The choice between them depends on the project's requirements and the desired level of networking control.

Go implementation of the Ethereum protocol

Pros of go-ethereum

  • More extensive and mature codebase, reflecting Ethereum's larger ecosystem
  • Broader functionality, including smart contract execution and EVM implementation
  • Higher community engagement and more frequent updates

Cons of go-ethereum

  • More complex codebase, potentially steeper learning curve for new contributors
  • Heavier resource requirements due to full node implementation
  • Slower transaction finality compared to Stellar's consensus mechanism

Code Comparison

go-ethereum (consensus mechanism):

func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
    header := block.Header()
    number := header.Number.Uint64()
    if number == 0 {
        return errUnknownBlock
    }
    // ...
}

stellar/go (consensus mechanism):

func (h *HerderImpl) triggerNextLedger(lastCloseTime time.Time) {
    h.triggerTimer.Cancel()
    h.nominationProtocol.stopNomination()
    h.ballotProtocol.stopBallot()
    h.valueOverrides = make(map[string]xdr.Value)
    // ...
}

Both repositories implement blockchain consensus mechanisms, but go-ethereum focuses on Proof-of-Work (transitioning to Proof-of-Stake), while stellar/go uses the Stellar Consensus Protocol. The code snippets showcase different approaches to block sealing and ledger closure, reflecting the distinct consensus models of each project.

15,649

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.

Pros of Fabric

  • More extensive enterprise-focused features for permissioned blockchain networks
  • Highly modular architecture allowing for customizable components
  • Supports multiple programming languages for smart contracts (chaincode)

Cons of Fabric

  • Steeper learning curve due to complex architecture
  • Requires more resources to set up and maintain
  • Less suitable for public, permissionless blockchain use cases

Code Comparison

Fabric (Go):

func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, value int) error {
    asset := Asset{ID: id, Value: value}
    assetJSON, err := json.Marshal(asset)
    if err != nil {
        return err
    }
    return ctx.GetStub().PutState(id, assetJSON)
}

Stellar (Go):

func CreateAccount(destination string) (xdr.Operation, error) {
    return xdr.Operation{
        SourceAccount: nil,
        Body: xdr.OperationBody{
            Type:            xdr.OperationTypeCreateAccount,
            CreateAccountOp: &xdr.CreateAccountOp{
                Destination: xdr.MustAddress(destination),
                StartingBalance: xdr.Int64(0),
            },
        },
    }, nil
}

The code snippets demonstrate the different approaches to asset creation in Fabric and account creation in Stellar. Fabric uses a more traditional smart contract structure, while Stellar focuses on operations within its network.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Stellar
Creating equitable access to the global financial system

Stellar Go Monorepo

master GitHub workflow GoDoc Go Report Card

This repo is the home for all of the public Go code produced by the Stellar Development Foundation.

This repo contains various tools and services that you can use and deploy, as well as the SDK you can use to develop applications that integrate with the Stellar network.

Package Index

  • Horizon Server: Full-featured API server for Stellar network
  • Go Horizon SDK - horizonclient: Client for Horizon server (queries and transaction submission)
  • Go Horizon SDK - txnbuild: Construct Stellar transactions and operations
  • Ticker: An API server that provides statistics about assets and markets on the Stellar network
  • Keystore: An API server that is used to store and manage encrypted keys for Stellar client applications
  • Servers for Anchors & Financial Institutions
    • Compliance Server: Allows financial institutions to exchange KYC information
    • Federation Server: Allows organizations to provide addresses for users (jane*examplebank.com)

Dependencies

This repository is officially supported on the last two releases of Go.

It depends on a number of external dependencies, and uses Go Modules to manage them. Running any go command will automatically download dependencies required for that operation.

You can choose to checkout this repository into a GOPATH or into any directory.

Directory Layout

In addition to the other top-level packages, there are a few special directories that contain specific types of packages:

  • clients contains packages that provide client packages to the various Stellar services.
  • exp contains experimental packages. Use at your own risk.
  • handlers contains packages that provide pluggable implementors of http.Handler that make it easier to incorporate portions of the Stellar protocol into your own http server.
  • support contains packages that are not intended for consumption outside of Stellar's other packages. Packages that provide common infrastructure for use in our services and tools should go here, such as db or log.
  • support/scripts contains single-file go programs and bash scripts used to support the development of this repo.
  • services contains packages that compile to applications that are long-running processes (such as API servers).
  • tools contains packages that compile to command line applications.

Each of these directories have their own README file that explain further the nature of their contents.

Other packages

In addition to the packages described above, this repository contains various packages related to working with the Stellar network from a go program. It's recommended that you use godoc to browse the documentation for each.

Package source layout

While much of the code in individual packages is organized based upon different developers' personal preferences, many of the packages follow a simple convention for organizing the declarations inside of a package that aim to aid in your ability to find code.

In each package, there may be one or more of a set of common files:

  • errors.go: This file should contains declarations (both types and vars) for errors that are used by the package.
  • example_test.go: This file should contains example tests, as described at https://blog.golang.org/examples.
  • main.go/internal.go (deprecated): Older packages may have a main.go (public symbols) or internal.go (private symbols). These files contain, respectively, the exported and unexported vars, consts, types and funcs for the package. New packages do not follow this pattern, and instead follow the standard Go convention to co-locate structs and their methods in the same files.
  • main.go (new convention): If present, this file contains a main function as part of an executable main package.

In addition to the above files, a package often has files that contains code that is specific to one declared type. This file uses the snake case form of the type name (for example loggly_hook.go would correspond to the type LogglyHook). This file should contain method declarations, interface implementation assertions and any other declarations that are tied solely to that type.

Each non-test file can have a test counterpart like normal, whose name ends with _test.go. The common files described above also have their own test counterparts... for example internal_test.go should contains tests that test unexported behavior and more commonly test helpers that are unexported.

Generally, file contents are sorted by exported/unexported, then declaration type (ordered as consts, vars, types, then funcs), then finally alphabetically.

Test helpers

Often, we provide test packages that aid in the creation of tests that interact with our other packages. For example, the support/db package has the support/db/dbtest package underneath it that contains elements that make it easier to test code that accesses a SQL database. We've found that this pattern of having a separate test package maximizes flexibility and simplifies package dependencies.

Contributing

Contributions are welcome! See CONTRIBUTING.md for more details.

Developing

See GUIDE_FOR_DEVELOPERS.md for helpful instructions for getting started developing code in this repository.