Skip to content

ltp456/go-aptos-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-aptos-sdk

aptos rest api implementation of the go language version, generate address, sign transaction and others

Apots Node Api Doc

example

install

go get github.com/ltp456/go-aptos-sdk

use example

package main

import (
    "encoding/hex"
    "fmt"
    goaptossdk "github.com/ltp456/go-aptos-sdk"
    "github.com/ltp456/go-aptos-sdk/crypto"
)

func main() {

    // keypair
    seed, err := crypto.NewRandSeed()
    if err != nil {
        panic(err)
    }
    fmt.Printf("seed: %x\n", seed)
    keyPair, err := crypto.NewKeyPairFromSeed(seed)
    if err != nil {
        panic(err)
    }

    fmt.Printf("prinvateKey: %x\n", keyPair.Private())
    fmt.Printf("publicKey: %x\n", keyPair.Public())
    fmt.Printf("address: %x\n", keyPair.Address())

    // sign and verify
    message := []byte("apots")
    signature, err := keyPair.Sign(message)
    if err != nil {
        panic(err)
    }
    publicKey := keyPair.Public()
    verify, err := publicKey.Verify(message, signature)
    if err != nil {
        panic(err)
    }
    fmt.Printf("verify: %v\n", verify)

    // client
    endpoint := "https://fullnode.devnet.aptoslabs.com"
    apotsClient, err := goaptossdk.NewApotsClient(endpoint)
    if err != nil {
        panic(err)
    }

    //faucet
    faucetEndpoint := "https://faucet.devnet.aptoslabs.com"
    apotsClient.SetFaucetEndpoint(faucetEndpoint)
    resp, err := apotsClient.FaucetFundAccount("0x468f5ade8a4cb5e426bad07ad8d808fb067160bc506eab8620520f8a5a4a08c9", 50000)
    if err != nil {
        panic(err)
    }
    fmt.Println(resp)

    // transfer
    seedStr := "d6140d0340dbf501388905c0fbd1457315631fbadb7e1625259f4b0107ffedde"
    seed, err = hex.DecodeString(seedStr)
    if err != nil {
        panic(err)
    }
    sender := "0x468f5ade8a4cb5e426bad07ad8d808fb067160bc506eab8620520f8a5a4a08c9"
    recipient := "0x6ac297031be21d7d3b83e53f76aa803016c389cd4bcdd4d0928b7aaa80c6ff83"

    submitTransactionResp, err := apotsClient.Transfer(seed, sender, recipient, "1000", "1000", "1")
    if err != nil {
        panic(err)
    }
    fmt.Println(submitTransactionResp.Hash)

    // Ledger
    information, err := apotsClient.LedgerInformation()
    if err != nil {
        panic(err)
    }
    fmt.Println(information)

}

About

go-aptos-sdk is apots rest api implementation of the go language version

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages