go_aptos_sdk

package module
v0.0.0-...-f3a19db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

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)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApotsClient

type ApotsClient struct {
	// contains filtered or unexported fields
}

func NewApotsClient

func NewApotsClient(endpoint string) (*ApotsClient, error)

func (*ApotsClient) AccountModuleByID

func (ap *ApotsClient) AccountModuleByID(address, moduleName, version string) (*types.AccountModules, error)

func (*ApotsClient) AccountModules

func (ap *ApotsClient) AccountModules(address, version string) ([]types.AccountModules, error)

func (*ApotsClient) AccountResource

func (ap *ApotsClient) AccountResource(address string, options ...Value) ([]types.AccountResource, error)

func (*ApotsClient) AccountResourceByResType

func (ap *ApotsClient) AccountResourceByResType(address, resType, version string) (*types.AccountResource, error)

func (*ApotsClient) AccountTransactions

func (ap *ApotsClient) AccountTransactions(address string, start, limit int64) ([]types.Transaction, error)

func (*ApotsClient) ApotsBalance

func (ap *ApotsClient) ApotsBalance(address string) (*big.Int, error)

func (*ApotsClient) CreateTxSignMessage

func (ap *ApotsClient) CreateTxSignMessage(sender, sequenceNumber, maxGasAmount, gasUnitPrice,
	expirationTimestampSec string, payload form.Payload, options ...Value) (*types.SignMessage, error)

func (*ApotsClient) EventsByEventHandle

func (ap *ApotsClient) EventsByEventHandle(address, handle, fieldName string, start, limit int) ([]types.Event, error)

func (*ApotsClient) EventsByKey

func (ap *ApotsClient) EventsByKey(eventKey string) ([]types.Event, error)

func (*ApotsClient) FaucetFundAccount

func (ap *ApotsClient) FaucetFundAccount(address string, amount uint64) (string, error)

func (*ApotsClient) GetAccount

func (ap *ApotsClient) GetAccount(address string) (*types.Account, error)

func (*ApotsClient) LedgerInformation

func (ap *ApotsClient) LedgerInformation() (*types.LedgerInformation, error)

func (*ApotsClient) SetFaucetEndpoint

func (ap *ApotsClient) SetFaucetEndpoint(url string)

func (*ApotsClient) SimulateTransaction

func (ap *ApotsClient) SimulateTransaction(seed []byte, sender, recipient, amount, maxGasAmount, gasUnitPrice string, options ...Value) (*types.Transaction, error)

func (*ApotsClient) SubmitTransaction

func (ap *ApotsClient) SubmitTransaction(sender, sequenceNumber, maxGasAmount, gasUnitPrice,
	expirationTimestampSec string, payload form.Payload, signature form.Signature, options ...Value) (*types.SubmitTransactionResp, error)

func (*ApotsClient) TableItemByHandleAndKey

func (ap *ApotsClient) TableItemByHandleAndKey(tableHandle, keyType, valueType, key string) error

func (*ApotsClient) Transaction

func (ap *ApotsClient) Transaction(txHash string) (*types.Transaction, error)

func (*ApotsClient) Transactions

func (ap *ApotsClient) Transactions(start, limit int64) ([]types.Transaction, error)

func (*ApotsClient) Transfer

func (ap *ApotsClient) Transfer(seed []byte, sender, recipient, amount, maxGasAmount, gasUnitPrice string, options ...Value) (*types.SubmitTransactionResp, error)

type Params

type Params map[string]interface{}

func (Params) Encode

func (p Params) Encode() string

func (Params) SetValue

func (p Params) SetValue(key string, value interface{})

type Value

type Value struct {
	Key   string
	Value interface{}
}

type Values

type Values []Value

func (*Values) Add

func (ov *Values) Add(key string, value interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL