Skip to content

Go SDK Quickstart

  1. Install the Go SDK

    The SDK requires Go 1.25+.

    Terminal window
    mkdir aptos-go-quickstart
    cd aptos-go-quickstart
    go mod init example/aptos-go-quickstart
    go get github.com/aptos-labs/aptos-go-sdk
  2. Set up the Aptos client

    client, err := aptos.NewClient(aptos.DevnetConfig)
    if err != nil {
    panic("Failed to create client:" + err.Error())
    }
  3. Create and fund accounts

    NewEd25519Account returns both the account and an error.

    alice, err := aptos.NewEd25519Account()
    if err != nil {
    panic("Failed to create alice:" + err.Error())
    }
    bob, err := aptos.NewEd25519Account()
    if err != nil {
    panic("Failed to create bob:" + err.Error())
    }
    err = client.Fund(alice.Address, 1_000_000_000)
    if err != nil {
    panic("Failed to fund alice:" + err.Error())
    }

    On testnet, mint from the faucet page.

  4. Transfer APT

    Build an aptos_account::transfer payload, then sign, submit, and wait. BuildSignAndSubmitTransaction combines those steps.

    accountBytes, err := bcs.Serialize(&bob.Address)
    amountBytes, err := bcs.SerializeU64(1_000)
    resp, err := client.BuildSignAndSubmitTransaction(alice, aptos.TransactionPayload{
    Payload: &aptos.EntryFunction{
    Module: aptos.ModuleId{
    Address: aptos.AccountOne,
    Name: "aptos_account",
    },
    Function: "transfer",
    ArgTypes: []aptos.TypeTag{},
    Args: [][]byte{accountBytes, amountBytes},
    },
    })
    _, err = client.WaitForTransaction(resp.Hash)

    For the lower-level build → simulate → sign → submit → wait flow, see Building Transactions.

package main
import (
"fmt"
"github.com/aptos-labs/aptos-go-sdk"
"github.com/aptos-labs/aptos-go-sdk/bcs"
)
const (
FundAmount = 1_000_000_000
TransferAmount = 1_000
)
func main() {
client, err := aptos.NewClient(aptos.DevnetConfig)
if err != nil {
panic("Failed to create client:" + err.Error())
}
alice, err := aptos.NewEd25519Account()
if err != nil {
panic("Failed to create alice:" + err.Error())
}
bob, err := aptos.NewEd25519Account()
if err != nil {
panic("Failed to create bob:" + err.Error())
}
fmt.Printf("=== Addresses ===\n")
fmt.Printf("Alice: %s\n", alice.Address.String())
fmt.Printf("Bob: %s\n", bob.Address.String())
err = client.Fund(alice.Address, FundAmount)
if err != nil {
panic("Failed to fund alice:" + err.Error())
}
aliceBalance, err := client.AccountAPTBalance(alice.Address)
if err != nil {
panic("Failed to retrieve alice balance:" + err.Error())
}
bobBalance, err := client.AccountAPTBalance(bob.Address)
if err != nil {
panic("Failed to retrieve bob balance:" + err.Error())
}
fmt.Printf("=== Initial Balances ===\n")
fmt.Printf("Alice: %d\n", aliceBalance)
fmt.Printf("Bob: %d\n", bobBalance)
accountBytes, err := bcs.Serialize(&bob.Address)
if err != nil {
panic("Failed to serialize bob's address:" + err.Error())
}
amountBytes, err := bcs.SerializeU64(TransferAmount)
if err != nil {
panic("Failed to serialize transfer amount:" + err.Error())
}
resp, err := client.BuildSignAndSubmitTransaction(alice, aptos.TransactionPayload{
Payload: &aptos.EntryFunction{
Module: aptos.ModuleId{
Address: aptos.AccountOne,
Name: "aptos_account",
},
Function: "transfer",
ArgTypes: []aptos.TypeTag{},
Args: [][]byte{
accountBytes,
amountBytes,
},
},
})
if err != nil {
panic("Failed to submit transaction:" + err.Error())
}
_, err = client.WaitForTransaction(resp.Hash)
if err != nil {
panic("Failed to wait for transaction:" + err.Error())
}
aliceBalance, err = client.AccountAPTBalance(alice.Address)
if err != nil {
panic("Failed to retrieve alice balance:" + err.Error())
}
bobBalance, err = client.AccountAPTBalance(bob.Address)
if err != nil {
panic("Failed to retrieve bob balance:" + err.Error())
}
fmt.Printf("=== Final Balances ===\n")
fmt.Printf("Alice: %d\n", aliceBalance)
fmt.Printf("Bob: %d\n", bobBalance)
fmt.Printf("See txn: https://explorer.aptoslabs.com/txn/%s?network=devnet\n", resp.Hash)
}

Run it with:

Terminal window
go run quickstart.go

You just learned how to transfer APT by:

  1. Connecting to the network with aptos.NewClient.
  2. Creating and funding accounts.
  3. Submitting a transfer and waiting for execution.