A comprehensive Go SDK for building applications on the Aptos blockchain.
- π 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
go get github.com/aptos-labs/aptos-go-sdkpackage 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)
}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// 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)txn, err := aptos.APTTransferTransaction(client, sender, receiver, amount)
signedTxn, err := txn.SignedTransaction(sender)
resp, err := client.SubmitTransaction(signedTxn)rawTxn, err := client.BuildTransaction(
sender.AccountAddress(),
payload,
aptos.MaxGasAmount(10_000),
aptos.GasUnitPrice(100),
aptos.ExpirationSeconds(300),
)rawTxn, err := client.BuildTransactionMultiAgent(
sender.AccountAddress(),
payload,
aptos.FeePayer(&feePayerAddress),
)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")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,
)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/- Clone the repository
- Make your changes
- Update
CHANGELOG.md - Run formatters and linters:
gofumpt -l -w . golangci-lint run - Run tests:
go test ./... - Submit a PR
- Update
CHANGELOG.mdwith a PR - Create a new tag (e.g.,
v1.12.0) with the list of changes
Apache 2.0 - See LICENSE for details.