aptos

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

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

Go to latest
Published: Aug 2, 2022 License: ISC Imports: 12 Imported by: 0

README

aptos-go

This is a pure Go implementation of the API's available in Aptos: https://aptos.dev.
This library offers all of the API's present in Aptos, as well as some utilities for generating and loading wallets, encrypting and verifying encrypted messages.

Requirements

Aptos node (you need to connect to an Aptos node to use this library, or run one yourself locally.)
Go 1.18 or newer

Installation
go get github.com/c-ollins/aptos-go
Usage example
func _main() error {
	client := aptos.NewAptosClient(NODE_URL)
	account1, err := aptos.AccountFromRandomKey()
	if err != nil {
		return err
	}

	err = client.FundFromFaucet(FAUCET_URL, account1.Address(), 5000)
	if err != nil {
		return err
	}

	balance1, err := client.AccountBalance(account1.Address())
	if err != nil {
		return err
	}
	fmt.Printf("account1 coins: %d. Should be 5000!\n", balance1)

	account2, err := aptos.AccountFromRandomKey()
	if err != nil {
		return err
	}

	err = client.FundFromFaucet(FAUCET_URL, account2.Address(), 0)
	if err != nil {
		return err
	}

	balance2, err := client.AccountBalance(account2.Address())
	if err != nil {
		return err
	}
	fmt.Printf("account2 coins: %d. Should be 0!\n", balance2)

	tx, err := client.SendCoinsSync(account1, account2.Address(), 717)
	if err != nil {
		return err
	}

	fmt.Println("Txn successful, Hash:", tx.Hash)

	balance2, err = client.AccountBalance(account2.Address())
	if err != nil {
		return err
	}

	fmt.Printf("account2 coins: %d. Should be 717!\n", balance2)
	return nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	SequenceNumber uint64 `json:"sequence_number,string"`
	AuthKey        string `json:"authentication_key"`
}

type AccountModule

type AccountModule struct {
	ByteCode string         `json:"bytecode"`
	ABI      *MoveModuleABI `json:"abi"`
}

type AccountResource

type AccountResource struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data"`
}

type AptosAccount

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

func AccountFromPrivateKey

func AccountFromPrivateKey(privateKey string) (*AptosAccount, error)

func AccountFromRandomKey

func AccountFromRandomKey() (*AptosAccount, error)

func (*AptosAccount) Address

func (aa *AptosAccount) Address() string

func (*AptosAccount) PublicKey

func (aa *AptosAccount) PublicKey() string

func (*AptosAccount) SignMessage

func (aa *AptosAccount) SignMessage(msg []byte) []byte

func (*AptosAccount) VerifyMessage

func (aa *AptosAccount) VerifyMessage(sig, msg []byte) bool

type AptosClient

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

func NewAptosClient

func NewAptosClient(nodeURL string) *AptosClient

func (*AptosClient) Account

func (ac *AptosClient) Account(address string) (*Account, error)

func (*AptosClient) AccountBalance

func (ac *AptosClient) AccountBalance(address string) (int64, error)

func (*AptosClient) AccountModuleByID

func (ac *AptosClient) AccountModuleByID(address, moduleID, version string) (*AccountModule, error)

TODO: test function

func (*AptosClient) AccountModules

func (ac *AptosClient) AccountModules(address, version string) ([]AccountModule, error)

TODO: test function

func (*AptosClient) AccountResourceByType

func (ac *AptosClient) AccountResourceByType(address, resourceType, version string) (*AccountResource, error)

func (*AptosClient) AccountResources

func (ac *AptosClient) AccountResources(address, version string) ([]AccountResource, error)

func (*AptosClient) AccountTransactions

func (ac *AptosClient) AccountTransactions(address string, limit, start int) ([]Transaction, error)

func (*AptosClient) CreateSigningMessage

func (ac *AptosClient) CreateSigningMessage(unsignedTx *UnsignedTx) (*SigningMessage, error)

func (*AptosClient) FundFromFaucet

func (ac *AptosClient) FundFromFaucet(faucetURL, address string, amount int64) error

TODO: decimal places

func (*AptosClient) GenerateTransaction

func (ac *AptosClient) GenerateTransaction(account *AptosAccount, payload interface{}) (*UnsignedTx, error)

func (*AptosClient) LedgerInfo

func (ac *AptosClient) LedgerInfo() (*LedgerInfo, error)

func (*AptosClient) SendCoins

func (ac *AptosClient) SendCoins(account *AptosAccount, destAddr string, amount int64) (*Transaction, error)

func (*AptosClient) SendCoinsSync

func (ac *AptosClient) SendCoinsSync(account *AptosAccount, destAddr string, amount int64) (*Transaction, error)

func (*AptosClient) SignTransaction

func (ac *AptosClient) SignTransaction(account *AptosAccount, unsignedTx *UnsignedTx) (*SignedTx, error)

func (*AptosClient) SubmitTransaction

func (ac *AptosClient) SubmitTransaction(signedTx *SignedTx) (*Transaction, error)

func (*AptosClient) Transaction

func (ac *AptosClient) Transaction(hashOrVersion string) (*Transaction, error)

func (*AptosClient) TransactionPending

func (ac *AptosClient) TransactionPending(txnHash string) (bool, error)

func (*AptosClient) Transactions

func (ac *AptosClient) Transactions(limit, start int) ([]Transaction, error)

func (*AptosClient) WaitForTransaction

func (ac *AptosClient) WaitForTransaction(txnHash string) error

type LedgerInfo

type LedgerInfo struct {
	ChainID         int32  `json:"chain_id"`
	LedgerVersion   uint   `json:"ledger_version,string"`
	LedgerTimestamp uint64 `json:"ledger_timestamp,string"`
}

type MoveFunction

type MoveFunction struct {
	Name              string        `json:"name"`
	Visibility        string        `json:"visibility"`
	GenericTypeParams []interface{} `json:"generic_type_params"`
	Params            []string      `json:"params"`
	Returns           []string      `json:"returns"`
}

type MoveModuleABI

type MoveModuleABI struct {
	Address string   `json:"address"`
	Name    string   `json:"string"`
	Friends []string `json:"friends"`
}

type MoveStruct

type MoveStruct struct {
	Name              string        `json:"name"`
	IsNative          bool          `json:"is_native"`
	Abilities         []string      `json:"abilities"`
	GenericTypeParams []interface{} `json:"generic_type_params"`
}

type MoveStructField

type MoveStructField struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type ScriptFunctionPayload

type ScriptFunctionPayload struct {
	Type          string   `json:"type"`
	Function      string   `json:"function"`
	TypeArguments []string `json:"type_arguments"`
	Arguments     []string `json:"arguments"`
}

type SignedTx

type SignedTx struct {
	*UnsignedTx
	Signature *TxSignature `json:"signature"`
}

type SigningMessage

type SigningMessage struct {
	Message string `json:"message"`
}

type Transaction

type Transaction struct {
	Type                string           `json:"type"`
	Events              []TxEvents       `json:"events"`
	Payload             *WriteSetPayload `json:"payload"`
	Version             uint64           `json:"version,string"`
	SequenceNumber      uint64           `json:"sequence_number,string"`
	MaxGasAmount        uint64           `json:"max_gas_amount,string"`
	GasUnitPrice        uint64           `json:"gas_unit_price,string"`
	GasCurrencyCode     string           `json:"gas_currency_code"`
	ExpirationTime      uint64           `json:"expiration_timestamp_secs,string"`
	Sender              string           `json:"sender"`
	Hash                string           `json:"hash"`
	StateRootHash       string           `json:"state_root_hash"`
	EventRootHash       string           `json:"event_root_hash"`
	GasUsed             uint64           `json:"gas_used,string"`
	Success             bool             `json:"success"`
	VMStatus            string           `json:"vm_status"`
	AccumulatorRootHash string           `json:"accumulator_root_hash"`
	Changes             interface{}      `json:"changes"`
	Signature           interface{}      `json:"signature"`
}

type TxEvents

type TxEvents struct {
	Key            string      `json:"key"`
	SequenceNumber uint64      `json:"sequence_number"`
	Type           string      `json:"type"`
	Data           interface{} `json:"data"`
}

type TxSignature

type TxSignature struct {
	Type      string `json:"type"`
	PublicKey string `json:"public_key"`
	Signature string `json:"signature"`
}

type UnsignedTx

type UnsignedTx struct {
	Sender          string      `json:"sender"`
	SequenceNumber  uint64      `json:"sequence_number,string"`
	MaxGasAmount    uint64      `json:"max_gas_amount,string"`
	GasUnitPrice    uint64      `json:"gas_unit_price,string"`
	GasCurrencyCode string      `json:"gas_currency_code"`
	ExpirationTime  uint64      `json:"expiration_timestamp_secs,string"`
	Payload         interface{} `json:"payload"`
}

type WriteSetPayload

type WriteSetPayload struct {
	Type     string      `json:"type"`
	WriteSet interface{} `json:"write_set"`
}

Jump to

Keyboard shortcuts

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