MCPcopy Index your code
hub / github.com/aptos-labs/aptos-go-sdk

github.com/aptos-labs/aptos-go-sdk @v1.13.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.13.0 ↗ · + Follow
3,786 symbols 16,001 edges 246 files 1,966 documented · 52% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

bash 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: bash gofumpt -l -w . golangci-lint run
  4. Run tests: bash 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.

Extension points exported contracts — how you extend this code

TypeTagImpl (Interface)
TypeTagImpl is an interface describing all the different types of [TypeTag]. Unfortunately because of how serialization [38 …
typetag.go
AccountAuthenticatorImpl (Interface)
AccountAuthenticatorImpl an implementation of an authenticator to provide generic verification across multiple types. T [14 …
crypto/authenticator.go
Signer (Interface)
Signer a generic interface for any kind of signing [11 implementers]
crypto/crypto.go
Marshaler (Interface)
Marshaler is an interface for any type that can be serialized into BCS It's highly suggested to implement on a pointer [140 …
bcs/bcs.go
HTTPDoer (Interface)
HTTPDoer is an interface for making HTTP requests. This abstraction allows for custom HTTP clients, middleware, and easy [10 …
v2/client.go
TransactionAuthenticator (Interface)
TransactionAuthenticator is an interface for all transaction-level authenticators. This is different from AccountAuthent [42 …
v2/transaction_types.go
TypeTagImpl (Interface)
TypeTagImpl is implemented by all specific type tag types. [38 implementers]
v2/internal/types/typetag.go
TransactionImpl (Interface)
TransactionImpl is an interface for all transactions [8 implementers]
api/transactions.go

Core symbols most depended-on inside this repo

Error
called by 422
http.go
Error
called by 268
v2/internal/bcs/serializer.go
String
called by 223
v2/internal/types/typetag.go
Bytes
called by 130
v2/internal/crypto/crypto.go
GenerateEd25519PrivateKey
called by 122
v2/internal/crypto/ed25519.go
Verify
called by 109
v2/internal/crypto/crypto.go
Serialize
called by 103
bcs/serializer.go
Sign
called by 101
v2/internal/crypto/crypto.go

Shape

Function 1,906
Method 1,405
Struct 358
TypeAlias 58
Interface 50
FuncType 9

Languages

Go100%

Modules by API surface

v2/internal/bcs/bcs_test.go182 symbols
v2/internal/crypto/crypto_test.go156 symbols
v2/internal/types/typetag.go111 symbols
typetag.go111 symbols
client.go96 symbols
api/transactions.go73 symbols
v2/internal/crypto/keyless.go68 symbols
spec_bcs_test.go56 symbols
v2/testutil/testutil_test.go54 symbols
v2/iter/iter_test.go54 symbols
v2/transaction_types.go53 symbols
nodeClient.go52 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add aptos-go-sdk \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page