Skip to content

aptos-labs/aptos-go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

370 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov 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.

Looking for v2? The Aptos Go SDK v2 is a modern, idiomatic rewrite with context.Context support, functional options, Go 1.24+ features, and a fluent transaction builder. New projects should use v2.

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

See the v2 README and v2 GoDocs for details.

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() {
    client, err := aptos.NewClient(aptos.TestnetConfig)
    if err != nil {
        log.Fatal(err)
    }

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

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

    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 that also serve as integration tests:

Example Description
transfer_coin Basic APT transfer between accounts
sponsored_transaction Fee payer sponsored transactions
multi_agent Multi-signer transactions
fungible_asset Fungible asset operations
alternative_signing Secp256k1 and other signing schemes
external_signing External/hardware wallet signing
offchain_multisig Off-chain multi-signature transactions
onchain_multisig On-chain multi-signature transactions
orderless_transaction Orderless (sequence-number-free) transactions
performance_transaction High-throughput transaction submission
sending_concurrent_transactions Concurrent batch operations
script_transaction Execute Move scripts
script_args_transaction Move scripts with typed arguments
local_abi Code generation from local ABI files
remote_abi Code generation from on-chain ABIs

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

v2 (recommended for new projects)

v1

General

Development

  1. Clone the repository
  2. Make your changes
  3. Run formatters and linters:
    gofumpt -l -w .
    golangci-lint run
  4. Run tests:
    go test ./...
  5. 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.