Skip to content

aptos-labs/aptos-go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

332 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go Reference Go Report Card GitHub go.mod Go version GitHub Tag

Aptos Go SDK

A comprehensive Go SDK for building applications on the Aptos blockchain.

Features

  • πŸ” Multiple Key Types - Ed25519, Secp256k1, MultiKey, and MultiEd25519 support
  • πŸ’Έ Transaction Building - Simple and advanced transaction construction
  • 🎫 Sponsored Transactions - Fee payer and multi-agent transaction support
  • πŸ“Š Fungible Assets - Full FA standard support
  • 🏷️ ANS Integration - Aptos Names Service (.apt domain) resolution
  • πŸ“ˆ Telemetry - OpenTelemetry tracing and metrics
  • πŸ”§ Code Generation - Generate type-safe Go bindings from Move ABIs
  • ⚑ Concurrent Operations - Batch transaction submission

Installation

go get github.com/aptos-labs/aptos-go-sdk

Quick Start

package main

import (
    "fmt"
    "log"

    "github.com/aptos-labs/aptos-go-sdk"
)

func main() {
    // Create a client
    client, err := aptos.NewClient(aptos.TestnetConfig)
    if err != nil {
        log.Fatal(err)
    }

    // Create an account
    account, err := aptos.NewEd25519Account()
    if err != nil {
        log.Fatal(err)
    }

    // Fund it (testnet only)
    err = client.Fund(account.AccountAddress(), 100_000_000)
    if err != nil {
        log.Fatal(err)
    }

    // Check balance
    balance, err := client.AccountAPTBalance(account.AccountAddress())
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Balance: %d octas\n", balance)
}

Examples

The examples/ directory contains runnable examples:

Example Description
transfer_coin Basic APT transfer
sponsored_transaction Fee payer transactions
multi_agent Multi-signer transactions
fungible_asset Fungible asset operations
ans ANS domain resolution
telemetry_example OpenTelemetry integration
codegen Code generation from ABIs
sending_concurrent_transactions Batch operations

Run an example:

cd examples/transfer_coin
go run main.go

Network Configuration

// Testnet (recommended for development)
client, _ := aptos.NewClient(aptos.TestnetConfig)

// Devnet (resets weekly)
client, _ := aptos.NewClient(aptos.DevnetConfig)

// Mainnet
client, _ := aptos.NewClient(aptos.MainnetConfig)

// Local node
client, _ := aptos.NewClient(aptos.LocalnetConfig)

Building Transactions

Simple Transfer

txn, err := aptos.APTTransferTransaction(client, sender, receiver, amount)
signedTxn, err := txn.SignedTransaction(sender)
resp, err := client.SubmitTransaction(signedTxn)

With Options

rawTxn, err := client.BuildTransaction(
    sender.AccountAddress(),
    payload,
    aptos.MaxGasAmount(10_000),
    aptos.GasUnitPrice(100),
    aptos.ExpirationSeconds(300),
)

Sponsored Transaction

rawTxn, err := client.BuildTransactionMultiAgent(
    sender.AccountAddress(),
    payload,
    aptos.FeePayer(&feePayerAddress),
)

Aptos Names Service (ANS)

ansClient := aptos.NewANSClient(client)

// Resolve name to address
address, err := ansClient.Resolve("alice.apt")

// Get primary name for address
name, err := ansClient.GetPrimaryName(address)

// Check availability
available, err := ansClient.IsAvailable("myname")

Telemetry

Add OpenTelemetry observability:

import "github.com/aptos-labs/aptos-go-sdk/telemetry"

httpClient, _ := telemetry.NewInstrumentedHTTPClient(
    telemetry.WithServiceName("my-app"),
)
client, _ := aptos.NewNodeClientWithHttpClient(
    aptos.MainnetConfig.NodeUrl,
    aptos.MainnetConfig.ChainId,
    httpClient,
)

Code Generation

Generate type-safe Go code from Move ABIs:

# Install the generator
go install github.com/aptos-labs/aptos-go-sdk/cmd/aptosgen@latest

# Generate from on-chain module
aptosgen -address 0x1 -module coin -package coin -output coin/

# Generate from local ABI file
aptosgen -abi coin.json -package coin -output coin/

Documentation

Development

  1. Clone the repository
  2. Make your changes
  3. Update CHANGELOG.md
  4. Run formatters and linters:
    gofumpt -l -w .
    golangci-lint run
  5. Run tests:
    go test ./...
  6. Submit a PR

Publishing

  1. Update CHANGELOG.md with a PR
  2. Create a new tag (e.g., v1.12.0) with the list of changes

License

Apache 2.0 - See LICENSE for details.