Go SDK Quickstart
-
Install the Go SDK
The SDK requires Go 1.25+.
Terminal window mkdir aptos-go-quickstartcd aptos-go-quickstartgo mod init example/aptos-go-quickstartgo get github.com/aptos-labs/aptos-go-sdk -
Set up the Aptos client
client, err := aptos.NewClient(aptos.DevnetConfig)if err != nil {panic("Failed to create client:" + err.Error())} -
Create and fund accounts
NewEd25519Accountreturns 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.
-
Transfer APT
Build an
aptos_account::transferpayload, then sign, submit, and wait.BuildSignAndSubmitTransactioncombines 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.
Full Quickstart Code
Section titled “Full Quickstart Code”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:
go run quickstart.goSummary
Section titled “Summary”You just learned how to transfer APT by:
- Connecting to the network with
aptos.NewClient. - Creating and funding accounts.
- Submitting a transfer and waiting for execution.