aptos

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

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 18 Imported by: 0

README

aptos-sdk

Aptos SDK is used to interact with the Aptos blockchain, it contains various functions that can be used for web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/724165435/go-wallet-sdk/coins/aptos

Usage

New Address
	// address
	addr, err := aptos.NewAddress("1790962db820729606cd7b255ace1ac5ebb129ac8e9b2d8534d022194ab25b37", false)
	if err != nil {
		// todo
		fmt.Println(err)
	}

Transfer
	// transfer
	from := addr
	to := "0xedc4410aa38b512e3173fcd1e119abb13872d6928dce0842664ad6ada1ccd28"
	amount := 1000
	sequenceNumber := 1
	maxGasAmount := 10000
	gasUnitPrice := 100
	expirationTimestampSecs := time.Now().Unix() + 300
	chainId := 2
	seedHex := "1790962db820729606cd7b255ace1ac5ebb129ac8e9b2d8534d022194ab25b37"
	data, err := aptos.Transfer(from, uint64(sequenceNumber), uint64(maxGasAmount), uint64(gasUnitPrice), uint64(expirationTimestampSecs), uint8(chainId),
		to, uint64(amount), seedHex)
	if err != nil {
		// todo
		fmt.Println(err)
	}
	fmt.Println(data)
TransferV2
	from := "0xd1028d1c19e05b737a5ff9e2bfddee4821d329f1b1efd9e21c002aea04b83862"
	to := "0x00ca226de86c2da6716aaeddfddc2a16c76d35c67a0da2148c408d2ea1e5ad38"
	amount := 100
	sequenceNumber := 15
	maxGasAmount := 200000
	gasUnitPrice := 100
	expirationTimestampSecs := 1722564321
	chainId := 1
	seedHex := "1790962db820729606cd7b255ace1ac5ebb129ac8e9b2d8534d022194ab25b37"
	payload, err := CoinTransferPayloadV2(to, uint64(amount), "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT")

    if err != nil {
        // todo
        fmt.Println(err)
    }
	data, err := BuildSignedTransaction(from, uint64(sequenceNumber), uint64(maxGasAmount), uint64(gasUnitPrice), uint64(expirationTimestampSecs), uint8(chainId), payload, seedHex)
    if err != nil {
        // todo
        fmt.Println(err)
    }
TransferCoin
	from := "0xd1028d1c19e05b737a5ff9e2bfddee4821d329f1b1efd9e21c002aea04b83862"
	to := "0x00ca226de86c2da6716aaeddfddc2a16c76d35c67a0da2148c408d2ea1e5ad38"
	amount := uint64(100)
	sequenceNumber := uint64(15)
	maxGasAmount := uint64(200000)
	gasUnitPrice := uint64(100)
	expirationTimestampSecs := uint64(1722564321)
	chainId := uint8(1)
	seedHex := "1790962db820729606cd7b255ace1ac5ebb129ac8e9b2d8534d022194ab25b37"
	tyArgs := "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT"

	data, err := TransferCoins(from, sequenceNumber, maxGasAmount, gasUnitPrice, expirationTimestampSecs, chainId, to, amount, seedHex, tyArgs)
    if err != nil {
        // todo
        fmt.Println(err)
    }

Credits This project includes code adapted from the following sources:

If you are the original author and would like credit adjusted, please contact us.

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

View Source
const (
	PrivateKeyEd25519Prefix    = "ed25519-priv-"
	PrivateKeyVariantSecp256k1 = "secp256k1-priv-"
)
View Source
const HexPrefix = "0x"

Variables

This section is empty.

Functions

func AddStake

func AddStake(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	poolAddress string, amount uint64, seedHex string) (string, error)

Staking related

func AddStakePayload

func AddStakePayload(poolAddress string, amount uint64) (aptos_types.TransactionPayload, error)

func BuildMultiAgentTx

func BuildMultiAgentTx(sender string, sequenceNumber uint64, maxGasAmount uint64,
	gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8, payload v2.TransactionPayload,
	feePayer string, additionalSigners []string) (rawTxnImpl *v2.RawTransactionWithData, err error)

func BuildScriptPayload

func BuildScriptPayload(payload string) (*v2.TransactionPayload, error)

func BuildSignedTransaction

func BuildSignedTransaction(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	payload aptos_types.TransactionPayload, seedHex string) (string, error)

func BuildSignedTransactionV2

func BuildSignedTransactionV2(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	payload *v2.TransactionPayload, seedHex string) (string, error)

func BuildTransferWithFeePayerTx

func BuildTransferWithFeePayerTx(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	to string, amount uint64, feePayer string) (*v2.RawTransactionWithData, error)

func ClaimNFTTokenPayload

func ClaimNFTTokenPayload(sender string, creator string, collectionName string, tokenName string, propertyVersion uint64) aptos_types.TransactionPayload

func CoinBurnPayload

func CoinBurnPayload(amount uint64, tyArg string) (aptos_types.TransactionPayload, error)

func CoinMintPayload

func CoinMintPayload(receiveAddress string, amount uint64, tyArg string) (aptos_types.TransactionPayload, error)

func CoinRegisterPayload

func CoinRegisterPayload(tyArg string) (aptos_types.TransactionPayload, error)

func CoinTransferPayload

func CoinTransferPayload(to string, amount uint64, tyArg string) (aptos_types.TransactionPayload, error)

func CoinTransferPayloadV2

func CoinTransferPayloadV2(to string, amount uint64, tyArg string) (aptos_types.TransactionPayload, error)

func ConvertArgs

func ConvertArgs(args []interface{}, argTypes []aptos_types.MoveType) ([][]byte, error)

func ConvertToBigInt

func ConvertToBigInt(v string) *big.Int

func DecodeHexStringErr

func DecodeHexStringErr(hexString string) ([]byte, error)

func DeserializeMultiAgentTransaction

func DeserializeMultiAgentTransaction(data []byte) (*v2.RawTransactionWithData, error)

DeserializeMultiAgentTransaction deserializes a BCS encoded MultiAgent transaction

func ExpandAddress

func ExpandAddress(address string) string

func GetAddressByPubKey

func GetAddressByPubKey(pubKeyHex string, shortEnable bool) (string, error)

func GetRandomPrivateKey

func GetRandomPrivateKey() (string, error)

func GetRawTxHash

func GetRawTxHash(rawTxn *aptos_types.RawTransaction) (string, error)

func GetSigningData

func GetSigningData(rawTxnImpl interface{}) (data []byte, err error)

func GetSigningHash

func GetSigningHash(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	to string, amount uint64) (string, error)

func GetTransactionHash

func GetTransactionHash(hexStr string) string

pub enum Transaction { /// Transaction submitted by the user. e.g: P2P payment transaction, publishing module /// transaction, etc. /// TODO: We need to rename SignedTransaction to SignedUserTransaction, as well as all the other /// transaction types we had in our codebase. UserTransaction(SignedTransaction),

/// Transaction that applies a WriteSet to the current storage, it's applied manually via db-bootstrapper. GenesisTransaction(WriteSetPayload),

/// Transaction to update the block metadata resource at the beginning of a block. BlockMetadata(BlockMetadata),

/// Transaction to let the executor update the global state tree and record the root hash /// in the TransactionInfo /// The hash value inside is unique block id which can generate unique hash of state checkpoint transaction StateCheckpoint(HashValue), }

func Interface2U64

func Interface2U64(value interface{}) (uint64, error)

func Interface2U128

func Interface2U128(value interface{}) (*serde.Uint128, error)

func MakeMultiAgentTransactionV2

func MakeMultiAgentTransactionV2(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64,
	expirationTimestampSecs uint64, chainId uint8, payload *v2.TransactionPayload, withFeePayer bool,
	feePayer string, additionalSigners []string) (*v2.RawTransactionWithData, error)

func MakeRawTransaction

func MakeRawTransaction(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64,
	expirationTimestampSecs uint64, chainId uint8, payload aptos_types.TransactionPayload) (*aptos_types.RawTransaction, error)

func MakeRawTransactionV2

func MakeRawTransactionV2(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64,
	expirationTimestampSecs uint64, chainId uint8, payload *v2.TransactionPayload) (*v2.RawTransaction, error)

func NewAddress

func NewAddress(seedHex string, shortEnable bool) string

func NewAddressFromPubkey

func NewAddressFromPubkey(pubkeyHex string) (addr string, err error)

func AddSignature(tx Transaction, sig []byte) (data TxData, err error)

func NewPubKeyAddress

func NewPubKeyAddress(pubHex string, shortEnable bool) (string, error)

func NewTxFromParam

func NewTxFromParam(txParam *AptosTXParam) (tx *v2.RawTransaction, err error)

func NewTxFromRaw

func NewTxFromRaw(rawTx string, isMultiAgent bool) (tx interface{}, err error)

todo

func OfferNFTTokenPayload

func OfferNFTTokenPayload(receiver string, creator string, collectionName string, tokenName string, propertyVersion uint64, amount uint64) aptos_types.TransactionPayload

func PayloadFromJsonAndAbi

func PayloadFromJsonAndAbi(payload string, abi string) (aptos_types.TransactionPayload, error)

func PayloadFromJsonAndAbiV2

func PayloadFromJsonAndAbiV2(payload string, abi string, options ...any) (*v2.TransactionPayload, error)

func PayloadFromSerializedHex

func PayloadFromSerializedHex(serializedHex string) (*v2.TransactionPayload, error)

func ReactivateStake

func ReactivateStake(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	poolAddress string, amount uint64, seedHex string) (string, error)

func ReactivateStakePayload

func ReactivateStakePayload(poolAddress string, amount uint64) (aptos_types.TransactionPayload, error)

func ShortenAddress

func ShortenAddress(address string) string

func SignAsFeePayer

func SignAsFeePayer(rawTxn, seedHex string, feePayer string) (string, string, error)

func SignMessage

func SignMessage(priKey, message string) (string, error)

func SignMultiAgentTx

func SignMultiAgentTx(rawTxn, seedHex string) (string, error)

func SignRawTransaction

func SignRawTransaction(rawTxn *aptos_types.RawTransaction, seedHex string) (string, error)

func SignRawTransactionV2

func SignRawTransactionV2(rawTxn *v2.RawTransaction, seedHex string) (string, error)

func SignSimpleTx

func SignSimpleTx(rawTxn, seedHex string) (string, error)

func SignedTx

func SignedTx(rawTxn *aptos_types.RawTransaction, signDataHex string, pubKey string) (string, error)

func SimulateTransaction

func SimulateTransaction(rawTxn *aptos_types.RawTransaction, seedHex string) (string, error)

func String2U128

func String2U128(str string) (*serde.Uint128, error)

func StripAptosPrivateKeyPrefix

func StripAptosPrivateKeyPrefix(privateKey string) string

func ToFinalMultiAgentTx

func ToFinalMultiAgentTx(txWithAuth *TxWithAuth) (string, error)

func Transfer

func Transfer(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	to string, amount uint64, seedHex string) (string, error)

func TransferCoins

func TransferCoins(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	to string, amount uint64, seedHex, tyArg string) (string, error)

func TransferPayload

func TransferPayload(to string, amount uint64) (aptos_types.TransactionPayload, error)

func Unlock

func Unlock(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	poolAddress string, amount uint64, seedHex string) (string, error)

func UnlockPayload

func UnlockPayload(poolAddress string, amount uint64) (aptos_types.TransactionPayload, error)

func V2CoinTransferPayload

func V2CoinTransferPayload(to string, amount uint64, tyArg string) (*v2.EntryFunction, error)

func ValidateAddress

func ValidateAddress(address string, shortEnable bool) bool

func ValidateContractAddress

func ValidateContractAddress(address string) bool

func VerifyMessage

func VerifyMessage(publicKey, message, signature string) error

func Withdraw

func Withdraw(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	poolAddress string, amount uint64, seedHex string) (string, error)

func WithdrawPayload

func WithdrawPayload(poolAddress string, amount uint64) (aptos_types.TransactionPayload, error)

Types

type AptosTXParam

type AptosTXParam struct {
	From                    string `json:"from"`
	SequenceNumber          uint64 `json:"sequenceNumber"`
	MaxGasAmount            uint64 `json:"maxGasAmount"`
	GasUnitPrice            uint64 `json:"gasUnitPrice"`
	ExpirationTimestampSecs uint64 `json:"expirationTimestampSecs"`
	ChainId                 uint8  `json:"chainId"`
	Payload                 string `json:"payload"`
}

type ScriptArgument

type ScriptArgument struct {
	Variant v2.ScriptArgumentVariant `json:"variant"` // The type of the argument
	Value   string                   `json:"value"`   // The value of the argument
}

ScriptArgument a Move script argument, which encodes its type with it

type ScriptParam

type ScriptParam struct {
	Code     string   `json:"code"`     // The compiled script bytes, hex
	ArgTypes []string `json:"argTypes"` // The types of the arguments
	Args     []string `json:"args"`     // The arguments
}

Script A Move script as compiled code as a transaction

type TxWithAuth

type TxWithAuth struct {
	RawTxn          *v2.RawTransactionWithData    `json:"rawTxn"`
	SenderAuth      *crypto.AccountAuthenticator  `json:"senderAuth"`
	FeePayerAuth    *crypto.AccountAuthenticator  `json:"feePayerAuth"`
	AdditionalAuths []crypto.AccountAuthenticator `json:"additionalAuths"`
}

func SignTxV2

func SignTxV2(rawTxnImpl *v2.RawTransactionWithData, seedHex string) (*TxWithAuth, error)

func TransferCoinsWithPayer

func TransferCoinsWithPayer(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	to string, amount uint64, seedHex, tyArg string, feePayer string) (*TxWithAuth, error)

func TransferWithFeePayer

func TransferWithFeePayer(from string, sequenceNumber uint64, maxGasAmount uint64, gasUnitPrice uint64, expirationTimestampSecs uint64, chainId uint8,
	to string, amount uint64, seedHex string, feePayer string) (*TxWithAuth, error)

func (*TxWithAuth) GetAdditionalAuthsHex

func (self *TxWithAuth) GetAdditionalAuthsHex() ([]string, error)

func (*TxWithAuth) GetFeePayerAuthHex

func (self *TxWithAuth) GetFeePayerAuthHex() (string, error)

func (*TxWithAuth) GetRawTxnHex

func (self *TxWithAuth) GetRawTxnHex() (string, error)

func (*TxWithAuth) GetSenderAuthHex

func (self *TxWithAuth) GetSenderAuthHex() (string, error)

func (*TxWithAuth) MarshalJson

func (self *TxWithAuth) MarshalJson() (string, error)

func (*TxWithAuth) UnmarshalJson

func (self *TxWithAuth) UnmarshalJson(dataJson string) error

type TxWithAuthJson

type TxWithAuthJson struct {
	RawTxn          string   `json:"rawTxn"`
	SenderAuth      string   `json:"senderAuth"`
	FeePayerAuth    string   `json:"feePayerAuth"`
	AdditionalAuths []string `json:"additionalAuths"`
}

Directories

Path Synopsis
v2
api
bcs
internal/types
Package types is an internal package that contains the types used in the Aptos Go SDK.
Package types is an internal package that contains the types used in the Aptos Go SDK.

Jump to

Keyboard shortcuts

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