Documentation ¶
Overview ¶
Package aptos is a Go interface into the Aptos blockchain.
The Aptos Go SDK provides a way to read on-chain data, submit transactions, and generally interact with the blockchain.
Quick links:
- Aptos Dev Docs for learning more about Aptos and how to use it.
- Examples are standalone runnable examples of how to use the SDK.
You can create a client and send a transfer transaction with the below example:
// Create a Client client := NewClient(DevnetConfig) // Create an account, and fund it account := NewEd25519Account() err := client.Fund(account.AccountAddress()) if err != nil { panic(fmt.Sprintf("Failed to fund account %s %w", account.AccountAddress().ToString(), err)) } // Send funds to a different address receiver := &AccountAddress{} receiver.ParseStringRelaxed("0xcafe") // Build a transaction to send 1 APT to the receiver amount := 100_000_000 // 1 APT transferTransaction, err := APTTransferTransaction(client, account, receiver, amount) if err != nil { panic(fmt.Sprintf("Failed to build transaction %w", err)) } // Submit transaction to the blockchain submitResponse, err := client.SubmitTransaction(transferTransaction) if err != nil { panic(fmt.Sprintf("Failed to submit transaction %w", err)) } // Wait for transaction to complete err := client.WaitForTransaction(submitResponse.Hash) if err != nil { panic(fmt.Sprintf("Failed to wait for transaction %w", err)) }
Index ¶
- Constants
- Variables
- func BytesToHex(bytes []byte) string
- func Get[T any](rc *NodeClient, getUrl string) (out T, err error)
- func ParseHex(hexStr string) ([]byte, error)
- func Post[T any](rc *NodeClient, postUrl string, contentType string, body io.Reader) (data T, err error)
- func RawTransactionPrehash() []byte
- func RawTransactionWithDataPrehash() []byte
- func Sha3256Hash(bytes [][]byte) (output []byte)
- func StrToBigInt(val string) (num *big.Int, err error)
- func StrToUint64(s string) (uint64, error)
- type Account
- type AccountAddress
- type AccountInfo
- type AccountResourceInfo
- type AccountResourceRecord
- type AdditionalSigners
- type AddressTag
- type AptosClient
- type AptosFaucetClient
- type AptosIndexerClient
- type AptosRpcClient
- type BoolTag
- type ChainIdOption
- type Client
- func (client *Client) Account(address AccountAddress, ledgerVersion ...uint64) (info AccountInfo, err error)
- func (client *Client) AccountAPTBalance(address AccountAddress, ledgerVersion ...uint64) (uint64, error)
- func (client *Client) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error)
- func (client *Client) AccountResources(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceInfo, err error)
- func (client *Client) AccountResourcesBCS(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceRecord, err error)
- func (client *Client) AccountTransactions(address AccountAddress, start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
- func (client *Client) BatchSubmitTransaction(signedTxns []*SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error)
- func (client *Client) BlockByHeight(blockHeight uint64, withTransactions bool) (data *api.Block, err error)
- func (client *Client) BlockByVersion(ledgerVersion uint64, withTransactions bool) (data *api.Block, err error)
- func (client *Client) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error)
- func (client *Client) BuildSignAndSubmitTransactions(sender TransactionSigner, payloads chan TransactionBuildPayload, ...)
- func (client *Client) BuildSignAndSubmitTransactionsWithSignFunction(sender AccountAddress, payloads chan TransactionBuildPayload, ...)
- func (client *Client) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)
- func (client *Client) BuildTransactionMultiAgent(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransactionWithData, err error)
- func (client *Client) BuildTransactions(sender AccountAddress, payloads chan TransactionBuildPayload, ...) (*RawTransaction, error)
- func (client *Client) EstimateGasPrice() (info EstimateGasInfo, err error)
- func (client *Client) FetchNextMultisigAddress(address AccountAddress) (*AccountAddress, error)
- func (client *Client) Fund(address AccountAddress, amount uint64) error
- func (client *Client) GetChainId() (chainId uint8, err error)
- func (client *Client) GetCoinBalances(address AccountAddress) ([]CoinBalance, error)
- func (client *Client) GetProcessorStatus(processorName string) (uint64, error)
- func (client *Client) Info() (info NodeInfo, err error)
- func (client *Client) NodeAPIHealthCheck(durationSecs ...uint64) (api.HealthCheckResponse, error)
- func (client *Client) PollForTransactions(txnHashes []string, options ...any) error
- func (client *Client) QueryIndexer(query any, variables map[string]any, options ...graphql.Option) error
- func (client *Client) RemoveHeader(key string)
- func (client *Client) SetHeader(key string, value string)
- func (client *Client) SetTimeout(timeout time.Duration)
- func (client *Client) SimulateTransaction(rawTxn *RawTransaction, sender TransactionSigner, options ...any) (data []*api.UserTransaction, err error)
- func (client *Client) SubmitTransaction(signedTransaction *SignedTransaction) (data *api.SubmitTransactionResponse, err error)
- func (client *Client) SubmitTransactions(requests chan TransactionSubmissionRequest, ...)
- func (client *Client) TransactionByHash(txnHash string) (data *api.Transaction, err error)
- func (client *Client) TransactionByVersion(version uint64) (data *api.CommittedTransaction, err error)
- func (client *Client) Transactions(start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
- func (client *Client) View(payload *ViewPayload, ledgerVersion ...uint64) (vals []any, err error)
- func (client *Client) WaitForTransaction(txnHash string, options ...any) (data *api.UserTransaction, err error)
- type CoinBalance
- type ConcResponse
- type Ed25519TransactionAuthenticator
- type EntryFunction
- func CoinBatchTransferPayload(coinType *TypeTag, dests []AccountAddress, amounts []uint64) (payload *EntryFunction, err error)
- func CoinTransferPayload(coinType *TypeTag, dest AccountAddress, amount uint64) (payload *EntryFunction, err error)
- func FungibleAssetPrimaryStoreTransferPayload(faMetadataAddress *AccountAddress, dest AccountAddress, amount uint64) (payload *EntryFunction, err error)
- func FungibleAssetTransferPayload(faMetadataAddress *AccountAddress, source AccountAddress, dest AccountAddress, ...) (payload *EntryFunction, err error)
- func MultisigAddOwnerPayload(owner AccountAddress) *EntryFunction
- func MultisigApprovePayload(multisigAddress AccountAddress, transactionId uint64) (*EntryFunction, error)
- func MultisigChangeThresholdPayload(numSignaturesRequired uint64) (*EntryFunction, error)
- func MultisigCreateAccountPayload(requiredSigners uint64, additionalAddresses []AccountAddress, ...) (*EntryFunction, error)
- func MultisigCreateTransactionPayload(multisigAddress AccountAddress, payload *MultisigTransactionPayload) (*EntryFunction, error)
- func MultisigCreateTransactionPayloadWithHash(multisigAddress AccountAddress, payload *MultisigTransactionPayload) (*EntryFunction, error)
- func MultisigRejectPayload(multisigAddress AccountAddress, transactionId uint64) (*EntryFunction, error)
- func MultisigRemoveOwnerPayload(owner AccountAddress) *EntryFunction
- type EstimateGasInfo
- type EstimateGasUnitPrice
- type EstimateMaxGasAmount
- type EstimatePrioritizedGasUnitPrice
- type ExpirationSeconds
- type FaucetClient
- type FeePayer
- type FeePayerTransactionAuthenticator
- type FungibleAssetClient
- func (client *FungibleAssetClient) Balance(storeAddress *AccountAddress, ledgerVersion ...uint64) (balance uint64, err error)
- func (client *FungibleAssetClient) Decimals() (decimals uint8, err error)
- func (client *FungibleAssetClient) IconUri(uri string, err error)
- func (client *FungibleAssetClient) IsFrozen(storeAddress *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error)
- func (client *FungibleAssetClient) IsUntransferable(storeAddress *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error)
- func (client *FungibleAssetClient) Maximum(ledgerVersion ...uint64) (maximum *big.Int, err error)
- func (client *FungibleAssetClient) Name() (name string, err error)
- func (client *FungibleAssetClient) PrimaryBalance(owner *AccountAddress, ledgerVersion ...uint64) (balance uint64, err error)
- func (client *FungibleAssetClient) PrimaryIsFrozen(owner *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error)
- func (client *FungibleAssetClient) PrimaryStoreAddress(owner *AccountAddress) (address *AccountAddress, err error)
- func (client *FungibleAssetClient) PrimaryStoreExists(owner *AccountAddress) (exists bool, err error)
- func (client *FungibleAssetClient) ProjectUri(uri string, err error)
- func (client *FungibleAssetClient) StoreExists(storeAddress *AccountAddress, ledgerVersion ...uint64) (exists bool, err error)
- func (client *FungibleAssetClient) StoreMetadata(storeAddress *AccountAddress, ledgerVersion ...uint64) (metadataAddress *AccountAddress, err error)
- func (client *FungibleAssetClient) Supply(ledgerVersion ...uint64) (supply *big.Int, err error)
- func (client *FungibleAssetClient) Symbol() (symbol string, err error)
- func (client *FungibleAssetClient) Transfer(sender TransactionSigner, senderStore AccountAddress, ...) (signedTxn *SignedTransaction, err error)
- func (client *FungibleAssetClient) TransferPrimaryStore(sender TransactionSigner, receiverAddress AccountAddress, amount uint64) (signedTxn *SignedTransaction, err error)
- type GasUnitPrice
- type HttpError
- type IndexerClient
- func (ic *IndexerClient) GetCoinBalances(address AccountAddress) ([]CoinBalance, error)
- func (ic *IndexerClient) GetProcessorStatus(processorName string) (uint64, error)
- func (ic *IndexerClient) Query(query any, variables map[string]any, options ...graphql.Option) error
- func (ic *IndexerClient) WaitOnIndexer(processorName string, requestedVersion uint64) error
- type MaxGasAmount
- type ModuleBundle
- type ModuleId
- type MultiAgentRawTransactionWithData
- type MultiAgentTransactionAuthenticator
- type MultiAgentWithFeePayerRawTransactionWithData
- type MultiEd25519TransactionAuthenticator
- type Multisig
- type MultisigTransactionImpl
- type MultisigTransactionPayload
- type MultisigTransactionPayloadVariant
- type NetworkConfig
- type NodeClient
- func (rc *NodeClient) Account(address AccountAddress, ledgerVersion ...uint64) (info AccountInfo, err error)
- func (rc *NodeClient) AccountAPTBalance(account AccountAddress, ledgerVersion ...uint64) (balance uint64, err error)
- func (rc *NodeClient) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error)
- func (rc *NodeClient) AccountResources(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceInfo, err error)
- func (rc *NodeClient) AccountResourcesBCS(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceRecord, err error)
- func (rc *NodeClient) AccountTransactions(account AccountAddress, start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
- func (rc *NodeClient) BatchSubmitTransaction(signedTxns []*SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error)
- func (rc *NodeClient) BatchSubmitTransactions(requests chan TransactionSubmissionRequest, ...)
- func (rc *NodeClient) BlockByHeight(blockHeight uint64, withTransactions bool) (data *api.Block, err error)
- func (rc *NodeClient) BlockByVersion(ledgerVersion uint64, withTransactions bool) (data *api.Block, err error)
- func (rc *NodeClient) BuildSignAndSubmitTransaction(sender TransactionSigner, payload TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error)
- func (rc *NodeClient) BuildSignAndSubmitTransactions(sender TransactionSigner, payloads chan TransactionBuildPayload, ...)
- func (rc *NodeClient) BuildSignAndSubmitTransactionsWithSignFunction(sender AccountAddress, payloads chan TransactionBuildPayload, ...)
- func (rc *NodeClient) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)
- func (rc *NodeClient) BuildTransactionMultiAgent(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxnImpl *RawTransactionWithData, err error)
- func (rc *NodeClient) BuildTransactions(sender AccountAddress, payloads chan TransactionBuildPayload, ...)
- func (rc *NodeClient) EstimateGasPrice() (info EstimateGasInfo, err error)
- func (rc *NodeClient) GetBCS(getUrl string) (out []byte, err error)
- func (rc *NodeClient) GetChainId() (chainId uint8, err error)
- func (rc *NodeClient) Info() (info NodeInfo, err error)
- func (rc *NodeClient) NodeHealthCheck(durationSecs ...uint64) (api.HealthCheckResponse, error)
- func (rc *NodeClient) PollForTransaction(hash string, options ...any) (*api.UserTransaction, error)
- func (rc *NodeClient) PollForTransactions(txnHashes []string, options ...any) error
- func (rc *NodeClient) RemoveHeader(key string)
- func (rc *NodeClient) SetHeader(key string, value string)
- func (rc *NodeClient) SetTimeout(timeout time.Duration)
- func (rc *NodeClient) SimulateTransaction(rawTxn *RawTransaction, sender TransactionSigner, options ...any) (data []*api.UserTransaction, err error)
- func (rc *NodeClient) SubmitTransaction(signedTxn *SignedTransaction) (data *api.SubmitTransactionResponse, err error)
- func (rc *NodeClient) SubmitTransactions(requests chan TransactionSubmissionRequest, ...)
- func (rc *NodeClient) TransactionByHash(txnHash string) (data *api.Transaction, err error)
- func (rc *NodeClient) TransactionByVersion(version uint64) (data *api.CommittedTransaction, err error)
- func (rc *NodeClient) Transactions(start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
- func (rc *NodeClient) View(payload *ViewPayload, ledgerVersion ...uint64) (data []any, err error)
- func (rc *NodeClient) WaitForTransaction(txnHash string, options ...any) (data *api.UserTransaction, err error)
- type NodeInfo
- type PollPeriod
- type PollTimeout
- type RawTransaction
- func (txn *RawTransaction) MarshalBCS(ser *bcs.Serializer)
- func (txn *RawTransaction) Sign(signer crypto.Signer) (authenticator *crypto.AccountAuthenticator, err error)
- func (txn *RawTransaction) SignedTransaction(sender crypto.Signer) (*SignedTransaction, error)
- func (txn *RawTransaction) SignedTransactionWithAuthenticator(auth *crypto.AccountAuthenticator) (*SignedTransaction, error)
- func (txn *RawTransaction) SigningMessage() (message []byte, err error)
- func (txn *RawTransaction) UnmarshalBCS(des *bcs.Deserializer)
- type RawTransactionImpl
- type RawTransactionWithData
- func (txn *RawTransactionWithData) MarshalBCS(ser *bcs.Serializer)
- func (txn *RawTransactionWithData) SetFeePayer(feePayer AccountAddress) bool
- func (txn *RawTransactionWithData) Sign(signer crypto.Signer) (authenticator *crypto.AccountAuthenticator, err error)
- func (txn *RawTransactionWithData) SigningMessage() (message []byte, err error)
- func (txn *RawTransactionWithData) ToFeePayerSignedTransaction(sender *crypto.AccountAuthenticator, ...) (*SignedTransaction, bool)
- func (txn *RawTransactionWithData) ToMultiAgentSignedTransaction(sender *crypto.AccountAuthenticator, ...) (*SignedTransaction, bool)
- func (txn *RawTransactionWithData) UnmarshalBCS(des *bcs.Deserializer)
- type RawTransactionWithDataImpl
- type RawTransactionWithDataVariant
- type Script
- type ScriptArgument
- type ScriptArgumentVariant
- type SequenceNumber
- type SequenceNumberTracker
- type SignedTransaction
- type SignedTransactionVariant
- type SignerTag
- type SingleSenderTransactionAuthenticator
- type StructTag
- type TransactionAuthenticator
- type TransactionAuthenticatorImpl
- type TransactionAuthenticatorVariant
- type TransactionBuildPayload
- type TransactionBuildResponse
- type TransactionPayload
- type TransactionPayloadImpl
- type TransactionPayloadVariant
- type TransactionSigner
- type TransactionSubmissionRequest
- type TransactionSubmissionResponse
- type TransactionSubmissionType
- type TypeTag
- type TypeTagImpl
- type TypeTagVariant
- type U128Tag
- type U16Tag
- type U256Tag
- type U32Tag
- type U64Tag
- type U8Tag
- type VectorTag
- type ViewPayload
Constants ¶
const ( DefaultMaxGasAmount = uint64(100_000) // Default to 0.001 APT max gas amount DefaultGasUnitPrice = uint64(100) // Default to min gas price DefaultExpirationSeconds = int64(300) // Default to 5 minutes )
const ClientHeader = "x-aptos-client"
ClientHeader is the header key for the SDK version
const ContentTypeAptosSignedTxnBcs = "application/x.aptos.signed_transaction+bcs"
ContentTypeAptosSignedTxnBcs header for sending BCS transaction payloads
const ContentTypeAptosViewFunctionBcs = "application/x.aptos.view_function+bcs"
ContentTypeAptosViewFunctionBcs header for sending BCS view function payloads
const HttpErrSummaryLength = 1000
HttpErrSummaryLength is the maximum length of the body to include in the error message
Variables ¶
var AccountFour = types.AccountFour
AccountFour represents the 0x4 address
var AccountOne = types.AccountOne
AccountOne represents the 0x1 address
var AccountThree = types.AccountThree
AccountThree represents the 0x3 address
var AccountTwo = types.AccountTwo
AccountTwo represents the 0x2 address
var AccountZero = types.AccountZero
AccountZero represents the 0x0 address
var AptosCoinTypeTag = TypeTag{&StructTag{ Address: AccountOne, Module: "aptos_coin", Name: "AptosCoin", }}
AptosCoinTypeTag is the TypeTag for 0x1::aptos_coin::AptosCoin
var ClientHeaderValue = "aptos-go-sdk/unk"
ClientHeaderValue is the header value for the SDK version
var DevnetConfig = NetworkConfig{
Name: "devnet",
NodeUrl: "https://api.devnet.aptoslabs.com/v1",
IndexerUrl: "https://api.devnet.aptoslabs.com/v1/graphql",
FaucetUrl: "https://faucet.devnet.aptoslabs.com/",
}
DevnetConfig is for use with devnet. Note devnet resets at least weekly. ChainId differs after each reset.
var LocalnetConfig = NetworkConfig{
Name: "localnet",
ChainId: 4,
NodeUrl: "http://127.0.0.1:8080/v1",
IndexerUrl: "http://127.0.0.1:8090/v1/graphql",
FaucetUrl: "http://127.0.0.1:8081",
}
LocalnetConfig is for use with a localnet, created by the [Aptos CLI](https://aptos.dev/tools/aptos-cli)
To start a localnet, install the Aptos CLI then run:
aptos node run-localnet --with-indexer-api
var MainnetConfig = NetworkConfig{
Name: "mainnet",
ChainId: 1,
NodeUrl: "https://api.mainnet.aptoslabs.com/v1",
IndexerUrl: "https://api.mainnet.aptoslabs.com/v1/graphql",
FaucetUrl: "",
}
MainnetConfig is for use with mainnet. There is no faucet for Mainnet, as these are real user assets.
var NamedNetworks map[string]NetworkConfig
NamedNetworks Map from network name to NetworkConfig
var TestnetConfig = NetworkConfig{
Name: "testnet",
ChainId: 2,
NodeUrl: "https://api.testnet.aptoslabs.com/v1",
IndexerUrl: "https://api.testnet.aptoslabs.com/v1/graphql",
FaucetUrl: "https://faucet.testnet.aptoslabs.com/",
}
TestnetConfig is for use with testnet. Testnet does not reset.
var TransactionPrefix *[]byte
TransactionPrefix is a cached hash prefix for taking transaction hashes
Functions ¶
func BytesToHex ¶ added in v0.3.0
BytesToHex converts bytes to a 0x prefixed hex string
func Get ¶ added in v0.4.0
func Get[T any](rc *NodeClient, getUrl string) (out T, err error)
Get makes a GET request to the endpoint and parses the response into the given type with JSON
func Post ¶ added in v0.4.0
func Post[T any](rc *NodeClient, postUrl string, contentType string, body io.Reader) (data T, err error)
Post makes a POST request to the endpoint with the given body and parses the response into the given type with JSON
func RawTransactionPrehash ¶
func RawTransactionPrehash() []byte
RawTransactionPrehash Return the sha3-256 prehash for RawTransaction Do not write to the []byte returned
func RawTransactionWithDataPrehash ¶ added in v0.2.0
func RawTransactionWithDataPrehash() []byte
RawTransactionWithDataPrehash Return the sha3-256 prehash for RawTransactionWithData Do not write to the []byte returned
func Sha3256Hash ¶ added in v0.2.0
Sha3256Hash takes a hash of the given sets of bytes
func StrToBigInt ¶ added in v0.3.0
StrToBigInt converts a string to a big.Int
func StrToUint64 ¶ added in v0.3.0
StrToUint64 converts a string to a uint64
Types ¶
type Account ¶
Account is a wrapper for a signer, handling the AccountAddress and signing
func NewAccountFromSigner ¶ added in v0.2.0
func NewAccountFromSigner(signer crypto.Signer, authKey ...crypto.AuthenticationKey) (*Account, error)
NewAccountFromSigner creates an account from a Signer, which is most commonly a private key
func NewEd25519Account ¶
NewEd25519Account creates a legacy Ed25519 account, this is most commonly used in wallets
func NewEd25519SingleSenderAccount ¶ added in v0.2.0
NewEd25519SingleSenderAccount creates a single signer Ed25519 account
func NewSecp256k1Account ¶ added in v0.2.0
NewSecp256k1Account creates a Secp256k1 account
type AccountAddress ¶
type AccountAddress = types.AccountAddress
AccountAddress is a 32 byte address on the Aptos blockchain It can represent an Object, an Account, and much more.
type AccountInfo ¶
type AccountInfo struct { SequenceNumberStr string `json:"sequence_number"` AuthenticationKeyHex string `json:"authentication_key"` }
AccountInfo is returned from calls to #Account()
func (AccountInfo) AuthenticationKey ¶
func (ai AccountInfo) AuthenticationKey() ([]byte, error)
AuthenticationKey Hex decode of AuthenticationKeyHex
func (AccountInfo) SequenceNumber ¶
func (ai AccountInfo) SequenceNumber() (uint64, error)
SequenceNumber ParseUint of SequenceNumberStr
type AccountResourceInfo ¶
type AccountResourceInfo struct { // e.g. "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>" Type string `json:"type"` // Decoded from Move contract data, could really be anything Data map[string]any `json:"data"` }
AccountResourceInfo is returned by #AccountResource() and #AccountResources()
type AccountResourceRecord ¶
type AccountResourceRecord struct { // Account::Module::Name Tag StructTag // BCS data as stored by Move contract Data []byte }
AccountResourceRecord DeserializeSequence[AccountResourceRecord](bcs) approximates the Rust side BTreeMap<StructTag,Vec<u8>> They should BCS the same with a prefix Uleb128 length followed by (StructTag,[]byte) pairs.
func (*AccountResourceRecord) MarshalBCS ¶
func (aar *AccountResourceRecord) MarshalBCS(ser *bcs.Serializer)
func (*AccountResourceRecord) UnmarshalBCS ¶
func (aar *AccountResourceRecord) UnmarshalBCS(des *bcs.Deserializer)
type AdditionalSigners ¶ added in v0.2.0
type AdditionalSigners []AccountAddress
AdditionalSigners will set the additional signers for a transaction
type AddressTag ¶ added in v0.2.0
type AddressTag struct{}
AddressTag represents the address type in Move
func (*AddressTag) GetType ¶ added in v0.2.0
func (xt *AddressTag) GetType() TypeTagVariant
func (*AddressTag) MarshalBCS ¶ added in v0.2.0
func (xt *AddressTag) MarshalBCS(_ *bcs.Serializer)
func (*AddressTag) String ¶ added in v0.2.0
func (xt *AddressTag) String() string
func (*AddressTag) UnmarshalBCS ¶ added in v0.2.0
func (xt *AddressTag) UnmarshalBCS(_ *bcs.Deserializer)
type AptosClient ¶ added in v1.0.0
type AptosClient interface { AptosRpcClient AptosIndexerClient AptosFaucetClient }
AptosClient is an interface for all functionality on the Client. It is a combination of AptosRpcClient, AptosIndexerClient, and AptosFaucetClient for the purposes of mocking and convenince.
type AptosFaucetClient ¶ added in v1.0.0
type AptosFaucetClient interface { // Fund Uses the faucet to fund an address, only applies to non-production networks Fund(address AccountAddress, amount uint64) error }
AptosFaucetClient is an interface for all functionality on the Client that is Faucet related. Its main implementation is FaucetClient
type AptosIndexerClient ¶ added in v1.0.0
type AptosIndexerClient interface { // QueryIndexer queries the indexer using GraphQL to fill the `query` struct with data. See examples in the indexer client on how to make queries // // var out []CoinBalance // var q struct { // Current_coin_balances []struct { // CoinType string `graphql:"coin_type"` // Amount uint64 // OwnerAddress string `graphql:"owner_address"` // } `graphql:"current_coin_balances(where: {owner_address: {_eq: $address}})"` // } // variables := map[string]any{ // "address": address.StringLong(), // } // err := client.QueryIndexer(&q, variables) // if err != nil { // return nil, err // } // // for _, coin := range q.Current_coin_balances { // out = append(out, CoinBalance{ // CoinType: coin.CoinType, // Amount: coin.Amount, // }) // } // // return out, nil QueryIndexer(query any, variables map[string]any, options ...graphql.Option) error // GetProcessorStatus returns the ledger version up to which the processor has processed GetProcessorStatus(processorName string) (uint64, error) // GetCoinBalances gets the balances of all coins associated with a given address GetCoinBalances(address AccountAddress) ([]CoinBalance, error) }
AptosIndexerClient is an interface for all functionality on the Client that is Indexer related. Its main implementation is IndexerClient
type AptosRpcClient ¶ added in v1.0.0
type AptosRpcClient interface { // SetTimeout adjusts the HTTP client timeout // // client.SetTimeout(5 * time.Millisecond) SetTimeout(timeout time.Duration) // SetHeader sets the header for all future requests // // client.SetHeader("Authorization", "Bearer abcde") SetHeader(key string, value string) // RemoveHeader removes the header from being automatically set all future requests. // // client.RemoveHeader("Authorization") RemoveHeader(key string) // Info Retrieves the node info about the network and it's current state Info() (info NodeInfo, err error) // Account Retrieves information about the account such as [SequenceNumber] and [crypto.AuthenticationKey] Account(address AccountAddress, ledgerVersion ...uint64) (info AccountInfo, err error) // AccountResource Retrieves a single resource given its struct name. // // address := AccountOne // dataMap, _ := client.AccountResource(address, "0x1::coin::CoinStore") // // Can also fetch at a specific ledger version // // address := AccountOne // dataMap, _ := client.AccountResource(address, "0x1::coin::CoinStore", 1) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error) // AccountResources fetches resources for an account into a JSON-like map[string]any in AccountResourceInfo.Data // For fetching raw Move structs as BCS, See #AccountResourcesBCS // // address := AccountOne // dataMap, _ := client.AccountResources(address) // // Can also fetch at a specific ledger version // // address := AccountOne // dataMap, _ := client.AccountResource(address, 1) AccountResources(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceInfo, err error) // AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in AccountResourceRecord.Data []byte AccountResourcesBCS(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceRecord, err error) // BlockByHeight fetches a block by height // // block, _ := client.BlockByHeight(1, false) // // Can also fetch with transactions // // block, _ := client.BlockByHeight(1, true) BlockByHeight(blockHeight uint64, withTransactions bool) (data *api.Block, err error) // BlockByVersion fetches a block by ledger version // // block, _ := client.BlockByVersion(123, false) // // Can also fetch with transactions // // block, _ := client.BlockByVersion(123, true) BlockByVersion(ledgerVersion uint64, withTransactions bool) (data *api.Block, err error) // TransactionByHash gets info on a transaction // The transaction may be pending or recently committed. // // data, err := client.TransactionByHash("0xabcd") // if err != nil { // if httpErr, ok := err.(aptos.HttpError) { // if httpErr.StatusCode == 404 { // // if we're sure this has been submitted, assume it is still pending elsewhere in the mempool // } // } // } else { // if data["type"] == "pending_transaction" { // // known to local mempool, but not committed yet // } // } TransactionByHash(txnHash string) (data *api.Transaction, err error) // TransactionByVersion gets info on a transaction from its LedgerVersion. It must have been // committed to have a ledger version // // data, err := client.TransactionByVersion("0xabcd") // if err != nil { // if httpErr, ok := err.(aptos.HttpError) { // if httpErr.StatusCode == 404 { // // if we're sure this has been submitted, the full node might not be caught up to this version yet // } // } // } TransactionByVersion(version uint64) (data *api.CommittedTransaction, err error) // PollForTransactions Waits up to 10 seconds for transactions to be done, polling at 10Hz // Accepts options PollPeriod and PollTimeout which should wrap time.Duration values. // // hashes := []string{"0x1234", "0x4567"} // err := client.PollForTransactions(hashes) // // Can additionally configure different options // // hashes := []string{"0x1234", "0x4567"} // err := client.PollForTransactions(hashes, PollPeriod(500 * time.Milliseconds), PollTimeout(5 * time.Seconds)) PollForTransactions(txnHashes []string, options ...any) error // WaitForTransaction Do a long-GET for one transaction and wait for it to complete // // data, err := client.WaitForTransaction("0x1234") WaitForTransaction(txnHash string, options ...any) (data *api.UserTransaction, err error) // Transactions Get recent transactions. // Start is a version number. Nil for most recent transactions. // Limit is a number of transactions to return. 'about a hundred' by default. // // client.Transactions(0, 2) // Returns 2 transactions // client.Transactions(1, 100) // Returns 100 transactions Transactions(start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error) // AccountTransactions Get transactions associated with an account. // Start is a version number. Nil for most recent transactions. // Limit is a number of transactions to return. 'about a hundred' by default. // // client.AccountTransactions(AccountOne, 0, 2) // Returns 2 transactions for 0x1 // client.AccountTransactions(AccountOne, 1, 100) // Returns 100 transactions for 0x1 AccountTransactions(address AccountAddress, start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error) // SubmitTransaction Submits an already signed transaction to the blockchain // // sender := NewEd25519Account() // txnPayload := TransactionPayload{ // Payload: &EntryFunction{ // Module: ModuleId{ // Address: AccountOne, // Name: "aptos_account", // }, // Function: "transfer", // ArgTypes: []TypeTag{}, // Args: [][]byte{ // dest[:], // amountBytes, // }, // } // } // rawTxn, _ := client.BuildTransaction(sender.AccountAddress(), txnPayload) // signedTxn, _ := sender.SignTransaction(rawTxn) // submitResponse, err := client.SubmitTransaction(signedTxn) SubmitTransaction(signedTransaction *SignedTransaction) (data *api.SubmitTransactionResponse, err error) // BatchSubmitTransaction submits a collection of signed transactions to the network in a single request // // It will return the responses in the same order as the input transactions that failed. If the response is empty, then // all transactions succeeded. // // sender := NewEd25519Account() // txnPayload := TransactionPayload{ // Payload: &EntryFunction{ // Module: ModuleId{ // Address: AccountOne, // Name: "aptos_account", // }, // Function: "transfer", // ArgTypes: []TypeTag{}, // Args: [][]byte{ // dest[:], // amountBytes, // }, // } // } // rawTxn, _ := client.BuildTransaction(sender.AccountAddress(), txnPayload) // signedTxn, _ := sender.SignTransaction(rawTxn) // submitResponse, err := client.BatchSubmitTransaction([]*SignedTransaction{signedTxn}) BatchSubmitTransaction(signedTxns []*SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error) // SimulateTransaction Simulates a raw transaction without sending it to the blockchain // // sender := NewEd25519Account() // txnPayload := TransactionPayload{ // Payload: &EntryFunction{ // Module: ModuleId{ // Address: AccountOne, // Name: "aptos_account", // }, // Function: "transfer", // ArgTypes: []TypeTag{}, // Args: [][]byte{ // dest[:], // amountBytes, // }, // } // } // rawTxn, _ := client.BuildTransaction(sender.AccountAddress(), txnPayload) // simResponse, err := client.SimulateTransaction(rawTxn, sender) SimulateTransaction(rawTxn *RawTransaction, sender TransactionSigner, options ...any) (data []*api.UserTransaction, err error) // GetChainId Retrieves the ChainId of the network // Note this will be cached forever, or taken directly from the config GetChainId() (chainId uint8, err error) // BuildTransaction Builds a raw transaction from the payload and fetches any necessary information from on-chain // // sender := NewEd25519Account() // txnPayload := TransactionPayload{ // Payload: &EntryFunction{ // Module: ModuleId{ // Address: AccountOne, // Name: "aptos_account", // }, // Function: "transfer", // ArgTypes: []TypeTag{}, // Args: [][]byte{ // dest[:], // amountBytes, // }, // } // } // rawTxn, err := client.BuildTransaction(sender.AccountAddress(), txnPayload) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error) // BuildTransactionMultiAgent Builds a raw transaction for MultiAgent or FeePayer from the payload and fetches any necessary information from on-chain // // sender := NewEd25519Account() // txnPayload := TransactionPayload{ // Payload: &EntryFunction{ // Module: ModuleId{ // Address: AccountOne, // Name: "aptos_account", // }, // Function: "transfer", // ArgTypes: []TypeTag{}, // Args: [][]byte{ // dest[:], // amountBytes, // }, // } // } // rawTxn, err := client.BuildTransactionMultiAgent(sender.AccountAddress(), txnPayload, FeePayer(AccountZero)) BuildTransactionMultiAgent(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransactionWithData, err error) // BuildSignAndSubmitTransaction Convenience function to do all three in one // for more configuration, please use them separately // // sender := NewEd25519Account() // txnPayload := TransactionPayload{ // Payload: &EntryFunction{ // Module: ModuleId{ // Address: AccountOne, // Name: "aptos_account", // }, // Function: "transfer", // ArgTypes: []TypeTag{}, // Args: [][]byte{ // dest[:], // amountBytes, // }, // } // } // submitResponse, err := client.BuildSignAndSubmitTransaction(sender, txnPayload) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error) // View Runs a view function on chain returning a list of return values. // // address := AccountOne // payload := &ViewPayload{ // Module: ModuleId{ // Address: AccountOne, // Name: "coin", // }, // Function: "balance", // ArgTypes: []TypeTag{AptosCoinTypeTag}, // Args: [][]byte{address[:]}, // } // vals, err := client.aptosClient.View(payload) // balance := StrToU64(vals.(any[])[0].(string)) View(payload *ViewPayload, ledgerVersion ...uint64) (vals []any, err error) // EstimateGasPrice Retrieves the gas estimate from the network. EstimateGasPrice() (info EstimateGasInfo, err error) // AccountAPTBalance retrieves the APT balance in the account AccountAPTBalance(address AccountAddress, ledgerVersion ...uint64) (uint64, error) // NodeAPIHealthCheck checks if the node is within durationSecs of the current time, if not provided the node default is used NodeAPIHealthCheck(durationSecs ...uint64) (api.HealthCheckResponse, error) }
AptosRpcClient is an interface for all functionality on the Client that is Node RPC related. Its main implementation is NodeClient
type BoolTag ¶
type BoolTag struct{}
BoolTag represents the bool type in Move
func (*BoolTag) GetType ¶
func (xt *BoolTag) GetType() TypeTagVariant
func (*BoolTag) MarshalBCS ¶
func (xt *BoolTag) MarshalBCS(_ *bcs.Serializer)
func (*BoolTag) UnmarshalBCS ¶
func (xt *BoolTag) UnmarshalBCS(_ *bcs.Deserializer)
type ChainIdOption ¶
type ChainIdOption uint8
ChainIdOption will set the chain ID for a transaction TODO: This one may want to be removed / renamed?
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a facade over the multiple types of underlying clients, as the user doesn't actually care where the data comes from. It will be then handled underneath
To create a new client, please use NewClient. An example below for Devnet:
client := NewClient(DevnetConfig)
Implements AptosClient
func NewClient ¶
func NewClient(config NetworkConfig, options ...any) (client *Client, err error)
NewClient Creates a new client with a specific network config that can be extended in the future
func (*Client) Account ¶
func (client *Client) Account(address AccountAddress, ledgerVersion ...uint64) (info AccountInfo, err error)
Account Retrieves information about the account such as SequenceNumber and crypto.AuthenticationKey
func (*Client) AccountAPTBalance ¶ added in v0.2.0
func (client *Client) AccountAPTBalance(address AccountAddress, ledgerVersion ...uint64) (uint64, error)
AccountAPTBalance retrieves the APT balance in the account
func (*Client) AccountResource ¶
func (client *Client) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error)
AccountResource Retrieves a single resource given its struct name.
address := AccountOne dataMap, _ := client.AccountResource(address, "0x1::coin::CoinStore")
Can also fetch at a specific ledger version
address := AccountOne dataMap, _ := client.AccountResource(address, "0x1::coin::CoinStore", 1)
func (*Client) AccountResources ¶
func (client *Client) AccountResources(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceInfo, err error)
AccountResources fetches resources for an account into a JSON-like map[string]any in AccountResourceInfo.Data For fetching raw Move structs as BCS, See #AccountResourcesBCS
address := AccountOne dataMap, _ := client.AccountResources(address)
Can also fetch at a specific ledger version
address := AccountOne dataMap, _ := client.AccountResource(address, 1)
func (*Client) AccountResourcesBCS ¶
func (client *Client) AccountResourcesBCS(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceRecord, err error)
AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in AccountResourceRecord.Data []byte
func (*Client) AccountTransactions ¶ added in v1.0.0
func (client *Client) AccountTransactions(address AccountAddress, start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
AccountTransactions Get transactions associated with an account. Start is a version number. Nil for most recent transactions. Limit is a number of transactions to return. 'about a hundred' by default.
client.AccountTransactions(AccountOne, 0, 2) // Returns 2 transactions for 0x1 client.AccountTransactions(AccountOne, 1, 100) // Returns 100 transactions for 0x1
func (*Client) BatchSubmitTransaction ¶ added in v0.6.0
func (client *Client) BatchSubmitTransaction(signedTxns []*SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error)
BatchSubmitTransaction submits a collection of signed transactions to the network in a single request
It will return the responses in the same order as the input transactions that failed. If the response is empty, then all transactions succeeded.
sender := NewEd25519Account() txnPayload := TransactionPayload{ Payload: &EntryFunction{ Module: ModuleId{ Address: AccountOne, Name: "aptos_account", }, Function: "transfer", ArgTypes: []TypeTag{}, Args: [][]byte{ dest[:], amountBytes, }, } } rawTxn, _ := client.BuildTransaction(sender.AccountAddress(), txnPayload) signedTxn, _ := sender.SignTransaction(rawTxn) submitResponse, err := client.BatchSubmitTransaction([]*SignedTransaction{signedTxn})
func (*Client) BlockByHeight ¶ added in v0.2.0
func (client *Client) BlockByHeight(blockHeight uint64, withTransactions bool) (data *api.Block, err error)
BlockByHeight fetches a block by height
block, _ := client.BlockByHeight(1, false)
Can also fetch with transactions
block, _ := client.BlockByHeight(1, true)
func (*Client) BlockByVersion ¶ added in v0.2.0
func (client *Client) BlockByVersion(ledgerVersion uint64, withTransactions bool) (data *api.Block, err error)
BlockByVersion fetches a block by ledger version
block, _ := client.BlockByVersion(123, false)
Can also fetch with transactions
block, _ := client.BlockByVersion(123, true)
func (*Client) BuildSignAndSubmitTransaction ¶
func (client *Client) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error)
BuildSignAndSubmitTransaction Convenience function to do all three in one for more configuration, please use them separately
sender := NewEd25519Account() txnPayload := TransactionPayload{ Payload: &EntryFunction{ Module: ModuleId{ Address: AccountOne, Name: "aptos_account", }, Function: "transfer", ArgTypes: []TypeTag{}, Args: [][]byte{ dest[:], amountBytes, }, } } submitResponse, err := client.BuildSignAndSubmitTransaction(sender, txnPayload)
func (*Client) BuildSignAndSubmitTransactions ¶ added in v0.6.0
func (client *Client) BuildSignAndSubmitTransactions( sender TransactionSigner, payloads chan TransactionBuildPayload, responses chan TransactionSubmissionResponse, buildOptions ...any, )
BuildSignAndSubmitTransactions starts up a goroutine to process transactions for a single [TransactionSender] Closes output chan `responses` on completion of input chan `payloads`.
func (*Client) BuildSignAndSubmitTransactionsWithSignFunction ¶ added in v0.6.0
func (client *Client) BuildSignAndSubmitTransactionsWithSignFunction( sender AccountAddress, payloads chan TransactionBuildPayload, responses chan TransactionSubmissionResponse, sign func(rawTxn RawTransactionImpl) (*SignedTransaction, error), buildOptions ...any, )
BuildSignAndSubmitTransactionsWithSignFunction allows for signing with a custom function
Closes output chan `responses` on completion of input chan `payloads`.
This enables the ability to do fee payer, and other approaches while staying concurrent
func Example() { client := NewNodeClient() sender := NewEd25519Account() feePayer := NewEd25519Account() payloads := make(chan TransactionBuildPayload) responses := make(chan TransactionSubmissionResponse) signingFunc := func(rawTxn RawTransactionImpl) (*SignedTransaction, error) { switch rawTxn.(type) { case *RawTransaction: return nil, fmt.Errorf("only fee payer supported") case *RawTransactionWithData: rawTxnWithData := rawTxn.(*RawTransactionWithData) switch rawTxnWithData.Variant { case MultiAgentRawTransactionWithDataVariant: return nil, fmt.Errorf("multi agent not supported, please provide a fee payer function") case MultiAgentWithFeePayerRawTransactionWithDataVariant: rawTxnWithData.Sign(sender) txn, ok := rawTxnWithData.ToFeePayerTransaction() default: return nil, fmt.Errorf("unsupported rawTransactionWithData type") } default: return nil, fmt.Errorf("unsupported rawTransactionImpl type") } } // startup worker go client.BuildSignAndSubmitTransactionsWithSignFunction( sender, payloads, responses, signingFunc ) // Here add payloads, and wiating on resposnes }
func (*Client) BuildTransaction ¶
func (client *Client) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)
BuildTransaction Builds a raw transaction from the payload and fetches any necessary information from on-chain
sender := NewEd25519Account() txnPayload := TransactionPayload{ Payload: &EntryFunction{ Module: ModuleId{ Address: AccountOne, Name: "aptos_account", }, Function: "transfer", ArgTypes: []TypeTag{}, Args: [][]byte{ dest[:], amountBytes, }, } } rawTxn, err := client.BuildTransaction(sender.AccountAddress(), txnPayload)
func (*Client) BuildTransactionMultiAgent ¶ added in v0.5.0
func (client *Client) BuildTransactionMultiAgent(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransactionWithData, err error)
BuildTransactionMultiAgent Builds a raw transaction for MultiAgent or FeePayer from the payload and fetches any necessary information from on-chain
sender := NewEd25519Account() txnPayload := TransactionPayload{ Payload: &EntryFunction{ Module: ModuleId{ Address: AccountOne, Name: "aptos_account", }, Function: "transfer", ArgTypes: []TypeTag{}, Args: [][]byte{ dest[:], amountBytes, }, } } rawTxn, err := client.BuildTransactionMultiAgent(sender.AccountAddress(), txnPayload, FeePayer(AccountZero))
func (*Client) BuildTransactions ¶ added in v0.6.0
func (client *Client) BuildTransactions(sender AccountAddress, payloads chan TransactionBuildPayload, responses chan TransactionBuildResponse, setSequenceNumber chan uint64, options ...any) (*RawTransaction, error)
BuildTransactions start a goroutine to process TransactionPayload and spit out RawTransactionImpl.
func (*Client) EstimateGasPrice ¶ added in v0.2.0
func (client *Client) EstimateGasPrice() (info EstimateGasInfo, err error)
EstimateGasPrice Retrieves the gas estimate from the network.
func (*Client) FetchNextMultisigAddress ¶ added in v0.2.0
func (client *Client) FetchNextMultisigAddress(address AccountAddress) (*AccountAddress, error)
FetchNextMultisigAddress retrieves the next multisig address to be created from the given account
func (*Client) Fund ¶
func (client *Client) Fund(address AccountAddress, amount uint64) error
Fund Uses the faucet to fund an address, only applies to non-production networks
func (*Client) GetChainId ¶
GetChainId Retrieves the ChainId of the network Note this will be cached forever, or taken directly from the config
func (*Client) GetCoinBalances ¶ added in v0.2.0
func (client *Client) GetCoinBalances(address AccountAddress) ([]CoinBalance, error)
GetCoinBalances gets the balances of all coins associated with a given address
func (*Client) GetProcessorStatus ¶ added in v0.2.0
GetProcessorStatus returns the ledger version up to which the processor has processed
func (*Client) NodeAPIHealthCheck ¶ added in v0.5.0
func (client *Client) NodeAPIHealthCheck(durationSecs ...uint64) (api.HealthCheckResponse, error)
NodeAPIHealthCheck checks if the node is within durationSecs of the current time, if not provided the node default is used
func (*Client) PollForTransactions ¶
PollForTransactions Waits up to 10 seconds for transactions to be done, polling at 10Hz Accepts options PollPeriod and PollTimeout which should wrap time.Duration values.
hashes := []string{"0x1234", "0x4567"} err := client.PollForTransactions(hashes)
Can additionally configure different options
hashes := []string{"0x1234", "0x4567"} err := client.PollForTransactions(hashes, PollPeriod(500 * time.Milliseconds), PollTimeout(5 * time.Seconds))
func (*Client) QueryIndexer ¶ added in v0.2.0
func (client *Client) QueryIndexer(query any, variables map[string]any, options ...graphql.Option) error
QueryIndexer queries the indexer using GraphQL to fill the `query` struct with data. See examples in the indexer client on how to make queries
var out []CoinBalance var q struct { Current_coin_balances []struct { CoinType string `graphql:"coin_type"` Amount uint64 OwnerAddress string `graphql:"owner_address"` } `graphql:"current_coin_balances(where: {owner_address: {_eq: $address}})"` } variables := map[string]any{ "address": address.StringLong(), } err := client.QueryIndexer(&q, variables) if err != nil { return nil, err } for _, coin := range q.Current_coin_balances { out = append(out, CoinBalance{ CoinType: coin.CoinType, Amount: coin.Amount, }) } return out, nil
func (*Client) RemoveHeader ¶ added in v0.6.0
RemoveHeader removes the header from being automatically set all future requests.
client.RemoveHeader("Authorization")
func (*Client) SetHeader ¶ added in v0.6.0
SetHeader sets the header for all future requests
client.SetHeader("Authorization", "Bearer abcde")
func (*Client) SetTimeout ¶
SetTimeout adjusts the HTTP client timeout
client.SetTimeout(5 * time.Millisecond)
func (*Client) SimulateTransaction ¶ added in v0.4.0
func (client *Client) SimulateTransaction(rawTxn *RawTransaction, sender TransactionSigner, options ...any) (data []*api.UserTransaction, err error)
SimulateTransaction Simulates a raw transaction without sending it to the blockchain
sender := NewEd25519Account() txnPayload := TransactionPayload{ Payload: &EntryFunction{ Module: ModuleId{ Address: AccountOne, Name: "aptos_account", }, Function: "transfer", ArgTypes: []TypeTag{}, Args: [][]byte{ dest[:], amountBytes, }, } } rawTxn, _ := client.BuildTransaction(sender.AccountAddress(), txnPayload) simResponse, err := client.SimulateTransaction(rawTxn, sender)
func (*Client) SubmitTransaction ¶
func (client *Client) SubmitTransaction(signedTransaction *SignedTransaction) (data *api.SubmitTransactionResponse, err error)
SubmitTransaction Submits an already signed transaction to the blockchain
sender := NewEd25519Account() txnPayload := TransactionPayload{ Payload: &EntryFunction{ Module: ModuleId{ Address: AccountOne, Name: "aptos_account", }, Function: "transfer", ArgTypes: []TypeTag{}, Args: [][]byte{ dest[:], amountBytes, }, } } rawTxn, _ := client.BuildTransaction(sender.AccountAddress(), txnPayload) signedTxn, _ := sender.SignTransaction(rawTxn) submitResponse, err := client.SubmitTransaction(signedTxn)
func (*Client) SubmitTransactions ¶ added in v0.6.0
func (client *Client) SubmitTransactions(requests chan TransactionSubmissionRequest, responses chan TransactionSubmissionResponse)
SubmitTransactions consumes signed transactions, submits to aptos-node, yields responses. closes output chan `responses` when input chan `signedTxns` is closed.
func (*Client) TransactionByHash ¶
func (client *Client) TransactionByHash(txnHash string) (data *api.Transaction, err error)
TransactionByHash gets info on a transaction The transaction may be pending or recently committed.
data, err := client.TransactionByHash("0xabcd") if err != nil { if httpErr, ok := err.(aptos.HttpError) { if httpErr.StatusCode == 404 { // if we're sure this has been submitted, assume it is still pending elsewhere in the mempool } } } else { if data["type"] == "pending_transaction" { // known to local mempool, but not committed yet } }
func (*Client) TransactionByVersion ¶
func (client *Client) TransactionByVersion(version uint64) (data *api.CommittedTransaction, err error)
TransactionByVersion gets info on a transaction from its LedgerVersion. It must have been committed to have a ledger version
data, err := client.TransactionByVersion("0xabcd") if err != nil { if httpErr, ok := err.(aptos.HttpError) { if httpErr.StatusCode == 404 { // if we're sure this has been submitted, the full node might not be caught up to this version yet } } }
func (*Client) Transactions ¶
func (client *Client) Transactions(start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
Transactions Get recent transactions. Start is a version number. Nil for most recent transactions. Limit is a number of transactions to return. 'about a hundred' by default.
client.Transactions(0, 2) // Returns 2 transactions client.Transactions(1, 100) // Returns 100 transactions
func (*Client) View ¶
func (client *Client) View(payload *ViewPayload, ledgerVersion ...uint64) (vals []any, err error)
View Runs a view function on chain returning a list of return values.
address := AccountOne payload := &ViewPayload{ Module: ModuleId{ Address: AccountOne, Name: "coin", }, Function: "balance", ArgTypes: []TypeTag{AptosCoinTypeTag}, Args: [][]byte{address[:]}, } vals, err := client.aptosClient.View(payload) balance := StrToU64(vals.(any[])[0].(string))
func (*Client) WaitForTransaction ¶
func (client *Client) WaitForTransaction(txnHash string, options ...any) (data *api.UserTransaction, err error)
WaitForTransaction Do a long-GET for one transaction and wait for it to complete
data, err := client.WaitForTransaction("0x1234")
type CoinBalance ¶ added in v0.2.0
type ConcResponse ¶ added in v0.3.0
ConcResponse is a concurrent response wrapper as a return type for all APIs. It is meant to specifically be used in channels.
type Ed25519TransactionAuthenticator ¶ added in v0.2.0
type Ed25519TransactionAuthenticator struct {
Sender *crypto.AccountAuthenticator
}
Ed25519TransactionAuthenticator for legacy ED25519 accounts Implements TransactionAuthenticatorImpl, bcs.Struct
func (*Ed25519TransactionAuthenticator) MarshalBCS ¶ added in v0.2.0
func (ea *Ed25519TransactionAuthenticator) MarshalBCS(ser *bcs.Serializer)
func (*Ed25519TransactionAuthenticator) UnmarshalBCS ¶ added in v0.2.0
func (ea *Ed25519TransactionAuthenticator) UnmarshalBCS(des *bcs.Deserializer)
func (*Ed25519TransactionAuthenticator) Verify ¶ added in v0.2.0
func (ea *Ed25519TransactionAuthenticator) Verify(msg []byte) bool
type EntryFunction ¶
EntryFunction call a single published entry function arguments are ordered BCS encoded bytes
func CoinBatchTransferPayload ¶ added in v0.3.0
func CoinBatchTransferPayload(coinType *TypeTag, dests []AccountAddress, amounts []uint64) (payload *EntryFunction, err error)
CoinBatchTransferPayload builds an EntryFunction payload for transferring coins to multiple receivers
Args:
- coinType is the type of coin to transfer. If none is provided, it will transfer 0x1::aptos_coin:AptosCoin
- dests are the destination [AccountAddress]s
- amounts are the amount of coins to transfer per destination
func CoinTransferPayload ¶ added in v0.2.0
func CoinTransferPayload(coinType *TypeTag, dest AccountAddress, amount uint64) (payload *EntryFunction, err error)
CoinTransferPayload builds an EntryFunction payload for transferring coins
Args:
- coinType is the type of coin to transfer. If none is provided, it will transfer 0x1::aptos_coin:AptosCoin
- dest is the destination AccountAddress
- amount is the amount of coins to transfer
func FungibleAssetPrimaryStoreTransferPayload ¶ added in v0.2.0
func FungibleAssetPrimaryStoreTransferPayload(faMetadataAddress *AccountAddress, dest AccountAddress, amount uint64) (payload *EntryFunction, err error)
FungibleAssetPrimaryStoreTransferPayload builds an EntryFunction payload to transfer between two primary stores. This is similar to CoinTransferPayload.
Args:
- faMetadataAddress is the AccountAddress of the metadata for the fungible asset
- dest is the destination AccountAddress
- amount is the amount of coins to transfer
Note: for now, if metadata is nil, then it will fail to build. But in the future, APT will be the default.
func FungibleAssetTransferPayload ¶ added in v0.2.0
func FungibleAssetTransferPayload(faMetadataAddress *AccountAddress, source AccountAddress, dest AccountAddress, amount uint64) (payload *EntryFunction, err error)
FungibleAssetTransferPayload builds an EntryFunction payload to transfer between two fungible asset stores
Args:
- faMetadataAddress is the AccountAddress of the metadata for the fungible asset
- source is the store AccountAddress to transfer from
- dest is the destination AccountAddress
- amount is the amount of coins to transfer
Note: for now, if metadata is nil, then it will fail to build. But in the future, APT will be the default
func MultisigAddOwnerPayload ¶ added in v0.2.0
func MultisigAddOwnerPayload(owner AccountAddress) *EntryFunction
MultisigAddOwnerPayload creates a payload to add an owner from the multisig
func MultisigApprovePayload ¶ added in v0.2.0
func MultisigApprovePayload(multisigAddress AccountAddress, transactionId uint64) (*EntryFunction, error)
MultisigApprovePayload generates a payload for approving a transaction on-chain. The caller must be an owner of the multisig
func MultisigChangeThresholdPayload ¶ added in v0.2.0
func MultisigChangeThresholdPayload(numSignaturesRequired uint64) (*EntryFunction, error)
MultisigChangeThresholdPayload creates a payload to change the number of signatures required for a transaction to pass.
For example, changing a 2-of-3 to a 3-of-3, the value for numSignaturesRequired would be 3
func MultisigCreateAccountPayload ¶ added in v0.2.0
func MultisigCreateAccountPayload(requiredSigners uint64, additionalAddresses []AccountAddress, metadataKeys []string, metadataValues []byte) (*EntryFunction, error)
MultisigCreateAccountPayload creates a payload for setting up a multisig
Required signers must be between 1 and the number of addresses total (sender + additional addresses). Metadata values must be BCS encoded values
func MultisigCreateTransactionPayload ¶ added in v0.2.0
func MultisigCreateTransactionPayload(multisigAddress AccountAddress, payload *MultisigTransactionPayload) (*EntryFunction, error)
MultisigCreateTransactionPayload creates a transaction to be voted upon in an on-chain multisig
Note, this serializes an EntryFunction payload, and sends it as an argument in the transaction. If the entry function payload is large, use MultisigCreateTransactionPayloadWithHash. The advantage of this over the hash version, is visibility on-chain.
func MultisigCreateTransactionPayloadWithHash ¶ added in v0.2.0
func MultisigCreateTransactionPayloadWithHash(multisigAddress AccountAddress, payload *MultisigTransactionPayload) (*EntryFunction, error)
MultisigCreateTransactionPayloadWithHash creates a transaction to be voted upon in an on-chain multisig
This differs from MultisigCreateTransactionPayload by instead taking a SHA3-256 hash of the payload and using that as the identifier of the transaction. The transaction intent will not be stored on-chain, only the hash of it.
func MultisigRejectPayload ¶ added in v0.2.0
func MultisigRejectPayload(multisigAddress AccountAddress, transactionId uint64) (*EntryFunction, error)
MultisigRejectPayload generates a payload for rejecting a transaction on-chain. The caller must be an owner of the multisig
func MultisigRemoveOwnerPayload ¶ added in v0.2.0
func MultisigRemoveOwnerPayload(owner AccountAddress) *EntryFunction
MultisigRemoveOwnerPayload creates a payload to remove an owner from the multisig
func (*EntryFunction) MarshalBCS ¶
func (sf *EntryFunction) MarshalBCS(ser *bcs.Serializer)
func (*EntryFunction) PayloadType ¶ added in v0.2.0
func (sf *EntryFunction) PayloadType() TransactionPayloadVariant
func (*EntryFunction) UnmarshalBCS ¶
func (sf *EntryFunction) UnmarshalBCS(des *bcs.Deserializer)
type EstimateGasInfo ¶ added in v0.2.0
type EstimateGasInfo struct { DeprioritizedGasEstimate uint64 `json:"deprioritized_gas_estimate"` // DeprioritizedGasEstimate is the gas estimate for a transaction that is willing to be deprioritized and pay less GasEstimate uint64 `json:"gas_estimate"` // GasEstimate is the gas estimate for a transaction that is willing to pay close to the median gas price PrioritizedGasEstimate uint64 `json:"prioritized_gas_estimate"` // PrioritizedGasEstimate is the gas estimate for a transaction that is willing to pay more to be prioritized }
EstimateGasInfo is returned by #EstimateGasPrice()
type EstimateGasUnitPrice ¶ added in v0.4.0
type EstimateGasUnitPrice bool
EstimateGasUnitPrice estimates the gas unit price for a transaction
type EstimateMaxGasAmount ¶ added in v0.4.0
type EstimateMaxGasAmount bool
EstimateMaxGasAmount estimates the max gas amount for a transaction
type EstimatePrioritizedGasUnitPrice ¶ added in v0.4.0
type EstimatePrioritizedGasUnitPrice bool
EstimatePrioritizedGasUnitPrice estimates the prioritized gas unit price for a transaction
type ExpirationSeconds ¶
type ExpirationSeconds int64
ExpirationSeconds will set the number of seconds from the current time to expire a transaction
type FaucetClient ¶
type FaucetClient struct {
// contains filtered or unexported fields
}
FaucetClient uses the underlying NodeClient to request for APT for gas on a network. This can only be used in a test network (e.g. Localnet, Devnet, Testnet)
func NewFaucetClient ¶ added in v0.2.0
func NewFaucetClient(nodeClient *NodeClient, faucetUrl string) (*FaucetClient, error)
NewFaucetClient creates a new client specifically for requesting faucet funds
func (*FaucetClient) Fund ¶
func (faucetClient *FaucetClient) Fund(address AccountAddress, amount uint64) error
Fund account with the given amount of AptosCoin
type FeePayer ¶ added in v0.2.0
type FeePayer *AccountAddress
FeePayer will set the fee payer for a transaction
type FeePayerTransactionAuthenticator ¶ added in v0.2.0
type FeePayerTransactionAuthenticator struct { Sender *crypto.AccountAuthenticator SecondarySignerAddresses []AccountAddress SecondarySigners []crypto.AccountAuthenticator FeePayer *AccountAddress FeePayerAuthenticator *crypto.AccountAuthenticator }
func (*FeePayerTransactionAuthenticator) MarshalBCS ¶ added in v0.2.0
func (ea *FeePayerTransactionAuthenticator) MarshalBCS(ser *bcs.Serializer)
func (*FeePayerTransactionAuthenticator) UnmarshalBCS ¶ added in v0.2.0
func (ea *FeePayerTransactionAuthenticator) UnmarshalBCS(des *bcs.Deserializer)
func (*FeePayerTransactionAuthenticator) Verify ¶ added in v0.2.0
func (ea *FeePayerTransactionAuthenticator) Verify(msg []byte) bool
type FungibleAssetClient ¶
type FungibleAssetClient struct {
// contains filtered or unexported fields
}
FungibleAssetClient This is an example client around a single fungible asset
func NewFungibleAssetClient ¶
func NewFungibleAssetClient(client *Client, metadataAddress *AccountAddress) (faClient *FungibleAssetClient, err error)
NewFungibleAssetClient verifies the AccountAddress of the metadata exists when creating the client
func (*FungibleAssetClient) Balance ¶
func (client *FungibleAssetClient) Balance(storeAddress *AccountAddress, ledgerVersion ...uint64) (balance uint64, err error)
Balance returns the balance of the store
func (*FungibleAssetClient) Decimals ¶
func (client *FungibleAssetClient) Decimals() (decimals uint8, err error)
Decimals returns the number of decimal places for the fungible asset
func (*FungibleAssetClient) IconUri ¶ added in v1.1.0
func (client *FungibleAssetClient) IconUri(uri string, err error)
IconUri returns the URI of the icon for the fungible asset
func (*FungibleAssetClient) IsFrozen ¶
func (client *FungibleAssetClient) IsFrozen(storeAddress *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error)
IsFrozen returns true if the store is frozen
func (*FungibleAssetClient) IsUntransferable ¶ added in v1.1.0
func (client *FungibleAssetClient) IsUntransferable(storeAddress *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error)
IsUntransferable returns true if the store can't be transferred
func (*FungibleAssetClient) Maximum ¶
func (client *FungibleAssetClient) Maximum(ledgerVersion ...uint64) (maximum *big.Int, err error)
Maximum returns the maximum possible supply of the fungible asset
func (*FungibleAssetClient) Name ¶
func (client *FungibleAssetClient) Name() (name string, err error)
Name returns the name of the fungible asset
func (*FungibleAssetClient) PrimaryBalance ¶
func (client *FungibleAssetClient) PrimaryBalance(owner *AccountAddress, ledgerVersion ...uint64) (balance uint64, err error)
PrimaryBalance returns the balance of the primary store for the owner
func (*FungibleAssetClient) PrimaryIsFrozen ¶
func (client *FungibleAssetClient) PrimaryIsFrozen(owner *AccountAddress, ledgerVersion ...uint64) (isFrozen bool, err error)
PrimaryIsFrozen returns true if the primary store for the owner is frozen
func (*FungibleAssetClient) PrimaryStoreAddress ¶
func (client *FungibleAssetClient) PrimaryStoreAddress(owner *AccountAddress) (address *AccountAddress, err error)
PrimaryStoreAddress returns the AccountAddress of the primary store for the owner
Note that the primary store may not exist at the address. Use FungibleAssetClient.PrimaryStoreExists to check.
func (*FungibleAssetClient) PrimaryStoreExists ¶
func (client *FungibleAssetClient) PrimaryStoreExists(owner *AccountAddress) (exists bool, err error)
PrimaryStoreExists returns true if the primary store for the owner exists
func (*FungibleAssetClient) ProjectUri ¶ added in v1.1.0
func (client *FungibleAssetClient) ProjectUri(uri string, err error)
ProjectUri returns the URI of the project for the fungible asset
func (*FungibleAssetClient) StoreExists ¶
func (client *FungibleAssetClient) StoreExists(storeAddress *AccountAddress, ledgerVersion ...uint64) (exists bool, err error)
StoreExists returns true if the store exists
func (*FungibleAssetClient) StoreMetadata ¶
func (client *FungibleAssetClient) StoreMetadata(storeAddress *AccountAddress, ledgerVersion ...uint64) (metadataAddress *AccountAddress, err error)
StoreMetadata returns the AccountAddress of the metadata for the store
func (*FungibleAssetClient) Supply ¶
func (client *FungibleAssetClient) Supply(ledgerVersion ...uint64) (supply *big.Int, err error)
Supply returns the total supply of the fungible asset
func (*FungibleAssetClient) Symbol ¶
func (client *FungibleAssetClient) Symbol() (symbol string, err error)
Symbol returns the symbol of the fungible asset
func (*FungibleAssetClient) Transfer ¶
func (client *FungibleAssetClient) Transfer(sender TransactionSigner, senderStore AccountAddress, receiverStore AccountAddress, amount uint64) (signedTxn *SignedTransaction, err error)
Transfer sends amount of the fungible asset from senderStore to receiverStore
func (*FungibleAssetClient) TransferPrimaryStore ¶
func (client *FungibleAssetClient) TransferPrimaryStore(sender TransactionSigner, receiverAddress AccountAddress, amount uint64) (signedTxn *SignedTransaction, err error)
TransferPrimaryStore sends amount of the fungible asset from the primary store of the sender to receiverAddress
type GasUnitPrice ¶
type GasUnitPrice uint64
GasUnitPrice will set the gas unit price in octas (1/10^8 APT) for a transaction
type HttpError ¶
type HttpError struct { Status string // HTTP status e.g. "200 OK" StatusCode int // HTTP status code e.g. 200 Header http.Header // HTTP headers Method string // HTTP method e.g. "GET" RequestUrl url.URL // URL of the request Body []byte // Body of the response }
HttpError is an error type that represents an error from a http request
func NewHttpError ¶
NewHttpError creates a new HttpError from a http.Response
type IndexerClient ¶ added in v0.2.0
type IndexerClient struct {
// contains filtered or unexported fields
}
IndexerClient is a GraphQL client specifically for requesting for data from the Aptos indexer
func NewIndexerClient ¶ added in v0.2.0
func NewIndexerClient(httpClient *http.Client, url string) *IndexerClient
NewIndexerClient creates a new client specifically for requesting data from the indexer
func (*IndexerClient) GetCoinBalances ¶ added in v0.2.0
func (ic *IndexerClient) GetCoinBalances(address AccountAddress) ([]CoinBalance, error)
GetCoinBalances retrieve the coin balances for all coins owned by the address
func (*IndexerClient) GetProcessorStatus ¶ added in v0.2.0
func (ic *IndexerClient) GetProcessorStatus(processorName string) (uint64, error)
GetProcessorStatus tells the most updated version of the transaction processor. This helps to determine freshness of data.
func (*IndexerClient) Query ¶ added in v0.2.0
func (ic *IndexerClient) Query(query any, variables map[string]any, options ...graphql.Option) error
Query is a generic function for making any GraphQL query against the indexer
func (*IndexerClient) WaitOnIndexer ¶ added in v0.2.0
func (ic *IndexerClient) WaitOnIndexer(processorName string, requestedVersion uint64) error
WaitOnIndexer waits for the indexer processorName specified to catch up to the requestedVersion
type MaxGasAmount ¶
type MaxGasAmount uint64
MaxGasAmount will set the max gas amount in gas units for a transaction
type ModuleBundle ¶
type ModuleBundle struct{}
ModuleBundle is long deprecated and no longer used, but exist as an enum position in TransactionPayload
func (*ModuleBundle) MarshalBCS ¶
func (txn *ModuleBundle) MarshalBCS(ser *bcs.Serializer)
func (*ModuleBundle) PayloadType ¶ added in v0.2.0
func (txn *ModuleBundle) PayloadType() TransactionPayloadVariant
func (*ModuleBundle) UnmarshalBCS ¶
func (txn *ModuleBundle) UnmarshalBCS(des *bcs.Deserializer)
type ModuleId ¶
type ModuleId struct { Address AccountAddress Name string }
ModuleId the identifier for a module e.g. 0x1::coin
func (*ModuleId) MarshalBCS ¶
func (mod *ModuleId) MarshalBCS(ser *bcs.Serializer)
func (*ModuleId) UnmarshalBCS ¶
func (mod *ModuleId) UnmarshalBCS(des *bcs.Deserializer)
type MultiAgentRawTransactionWithData ¶ added in v0.2.0
type MultiAgentRawTransactionWithData struct { RawTxn *RawTransaction SecondarySigners []AccountAddress }
func (*MultiAgentRawTransactionWithData) MarshalBCS ¶ added in v0.2.0
func (txn *MultiAgentRawTransactionWithData) MarshalBCS(ser *bcs.Serializer)
func (*MultiAgentRawTransactionWithData) UnmarshalBCS ¶ added in v0.2.0
func (txn *MultiAgentRawTransactionWithData) UnmarshalBCS(des *bcs.Deserializer)
type MultiAgentTransactionAuthenticator ¶ added in v0.2.0
type MultiAgentTransactionAuthenticator struct { Sender *crypto.AccountAuthenticator SecondarySignerAddresses []AccountAddress SecondarySigners []crypto.AccountAuthenticator }
func (*MultiAgentTransactionAuthenticator) MarshalBCS ¶ added in v0.2.0
func (ea *MultiAgentTransactionAuthenticator) MarshalBCS(ser *bcs.Serializer)
func (*MultiAgentTransactionAuthenticator) UnmarshalBCS ¶ added in v0.2.0
func (ea *MultiAgentTransactionAuthenticator) UnmarshalBCS(des *bcs.Deserializer)
func (*MultiAgentTransactionAuthenticator) Verify ¶ added in v0.2.0
func (ea *MultiAgentTransactionAuthenticator) Verify(msg []byte) bool
type MultiAgentWithFeePayerRawTransactionWithData ¶ added in v0.2.0
type MultiAgentWithFeePayerRawTransactionWithData struct { RawTxn *RawTransaction SecondarySigners []AccountAddress FeePayer *AccountAddress }
func (*MultiAgentWithFeePayerRawTransactionWithData) MarshalBCS ¶ added in v0.2.0
func (txn *MultiAgentWithFeePayerRawTransactionWithData) MarshalBCS(ser *bcs.Serializer)
func (*MultiAgentWithFeePayerRawTransactionWithData) UnmarshalBCS ¶ added in v0.2.0
func (txn *MultiAgentWithFeePayerRawTransactionWithData) UnmarshalBCS(des *bcs.Deserializer)
type MultiEd25519TransactionAuthenticator ¶ added in v0.2.0
type MultiEd25519TransactionAuthenticator struct {
Sender *crypto.AccountAuthenticator
}
func (*MultiEd25519TransactionAuthenticator) MarshalBCS ¶ added in v0.2.0
func (ea *MultiEd25519TransactionAuthenticator) MarshalBCS(ser *bcs.Serializer)
func (*MultiEd25519TransactionAuthenticator) UnmarshalBCS ¶ added in v0.2.0
func (ea *MultiEd25519TransactionAuthenticator) UnmarshalBCS(des *bcs.Deserializer)
func (*MultiEd25519TransactionAuthenticator) Verify ¶ added in v0.2.0
func (ea *MultiEd25519TransactionAuthenticator) Verify(msg []byte) bool
type Multisig ¶ added in v0.2.0
type Multisig struct { MultisigAddress AccountAddress Payload *MultisigTransactionPayload // Optional }
Multisig is an on-chain multisig transaction, that calls an entry function associated
func (*Multisig) MarshalBCS ¶ added in v0.2.0
func (sf *Multisig) MarshalBCS(ser *bcs.Serializer)
func (*Multisig) PayloadType ¶ added in v0.2.0
func (sf *Multisig) PayloadType() TransactionPayloadVariant
func (*Multisig) UnmarshalBCS ¶ added in v0.2.0
func (sf *Multisig) UnmarshalBCS(des *bcs.Deserializer)
type MultisigTransactionImpl ¶ added in v0.2.0
type MultisigTransactionPayload ¶ added in v0.2.0
type MultisigTransactionPayload struct { Variant MultisigTransactionPayloadVariant Payload MultisigTransactionImpl }
MultisigTransactionPayload is an enum allowing for multiple types of transactions to be called via multisig
Note this does not implement TransactionPayloadImpl
func (*MultisigTransactionPayload) MarshalBCS ¶ added in v0.2.0
func (sf *MultisigTransactionPayload) MarshalBCS(ser *bcs.Serializer)
func (*MultisigTransactionPayload) UnmarshalBCS ¶ added in v0.2.0
func (sf *MultisigTransactionPayload) UnmarshalBCS(des *bcs.Deserializer)
type MultisigTransactionPayloadVariant ¶ added in v0.2.0
type MultisigTransactionPayloadVariant uint32
const (
MultisigTransactionPayloadVariantEntryFunction MultisigTransactionPayloadVariant = 0
)
type NetworkConfig ¶
type NetworkConfig struct { Name string ChainId uint8 NodeUrl string IndexerUrl string FaucetUrl string }
NetworkConfig a configuration for the Client and which network to use. Use one of the preconfigured LocalnetConfig, DevnetConfig, TestnetConfig, or MainnetConfig unless you have your own full node.
Name, ChainId, IndexerUrl, FaucetUrl are not required.
If ChainId is 0, the ChainId wil be fetched on-chain If IndexerUrl or FaucetUrl are an empty string "", clients will not be made for them.
type NodeClient ¶
type NodeClient struct {
// contains filtered or unexported fields
}
NodeClient is a client for interacting with an Aptos node API
func NewNodeClient ¶ added in v0.2.0
func NewNodeClient(rpcUrl string, chainId uint8) (*NodeClient, error)
NewNodeClient creates a new client for interacting with an Aptos node API
func NewNodeClientWithHttpClient ¶ added in v0.2.0
func NewNodeClientWithHttpClient(rpcUrl string, chainId uint8, client *http.Client) (*NodeClient, error)
NewNodeClientWithHttpClient creates a new client for interacting with an Aptos node API with a custom http.Client
func (*NodeClient) Account ¶
func (rc *NodeClient) Account(address AccountAddress, ledgerVersion ...uint64) (info AccountInfo, err error)
Account gets information about an account for a given address
Optionally, a ledgerVersion can be given to get the account state at a specific ledger version
func (*NodeClient) AccountAPTBalance ¶ added in v0.2.0
func (rc *NodeClient) AccountAPTBalance(account AccountAddress, ledgerVersion ...uint64) (balance uint64, err error)
AccountAPTBalance fetches the balance of an account of APT. Response is in octas or 1/10^8 APT.
func (*NodeClient) AccountResource ¶
func (rc *NodeClient) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error)
AccountResource fetches a resource for an account into a JSON-like map[string]any. Optionally, a ledgerVersion can be given to get the account state at a specific ledger version
For fetching raw Move structs as BCS, See #AccountResourceBCS
func (*NodeClient) AccountResources ¶
func (rc *NodeClient) AccountResources(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceInfo, err error)
AccountResources fetches resources for an account into a JSON-like map[string]any in AccountResourceInfo.Data Optionally, a ledgerVersion can be given to get the account state at a specific ledger version For fetching raw Move structs as BCS, See #AccountResourcesBCS
func (*NodeClient) AccountResourcesBCS ¶
func (rc *NodeClient) AccountResourcesBCS(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceRecord, err error)
AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in AccountResourceRecord.Data []byte Optionally, a ledgerVersion can be given to get the account state at a specific ledger version
func (*NodeClient) AccountTransactions ¶ added in v1.0.0
func (rc *NodeClient) AccountTransactions(account AccountAddress, start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
AccountTransactions Get recent transactions for an account
Arguments:
- start is a version number. Nil for most recent transactions.
- limit is a number of transactions to return. 'about a hundred' by default.
func (*NodeClient) BatchSubmitTransaction ¶ added in v0.6.0
func (rc *NodeClient) BatchSubmitTransaction(signedTxns []*SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error)
BatchSubmitTransaction submits a collection of signed transactions to the network in a single request
It will return the responses in the same order as the input transactions that failed. If the response is empty, then all transactions succeeded.
func (*NodeClient) BatchSubmitTransactions ¶ added in v0.6.0
func (rc *NodeClient) BatchSubmitTransactions(requests chan TransactionSubmissionRequest, responses chan TransactionSubmissionResponse)
BatchSubmitTransactions consumes signed transactions, submits to aptos-node, yields responses. closes output chan `responses` when input chan `signedTxns` is closed.
func (*NodeClient) BlockByHeight ¶ added in v0.2.0
func (rc *NodeClient) BlockByHeight(blockHeight uint64, withTransactions bool) (data *api.Block, err error)
BlockByHeight gets a block by block height
The function will fetch all transactions in the block if withTransactions is true.
func (*NodeClient) BlockByVersion ¶ added in v0.2.0
func (rc *NodeClient) BlockByVersion(ledgerVersion uint64, withTransactions bool) (data *api.Block, err error)
BlockByVersion gets a block by a transaction's version number
Note that this is not the same as a block's height.
The function will fetch all transactions in the block if withTransactions is true.
func (*NodeClient) BuildSignAndSubmitTransaction ¶
func (rc *NodeClient) BuildSignAndSubmitTransaction(sender TransactionSigner, payload TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error)
BuildSignAndSubmitTransaction builds, signs, and submits a transaction to the network
func (*NodeClient) BuildSignAndSubmitTransactions ¶ added in v0.4.0
func (rc *NodeClient) BuildSignAndSubmitTransactions( sender TransactionSigner, payloads chan TransactionBuildPayload, responses chan TransactionSubmissionResponse, buildOptions ...any, )
BuildSignAndSubmitTransactions starts up a goroutine to process transactions for a single [TransactionSender] Closes output chan `responses` on completion of input chan `payloads`.
func (*NodeClient) BuildSignAndSubmitTransactionsWithSignFunction ¶ added in v0.4.0
func (rc *NodeClient) BuildSignAndSubmitTransactionsWithSignFunction( sender AccountAddress, payloads chan TransactionBuildPayload, responses chan TransactionSubmissionResponse, sign func(rawTxn RawTransactionImpl) (*SignedTransaction, error), buildOptions ...any, )
BuildSignAndSubmitTransactionsWithSignFunction allows for signing with a custom function
Closes output chan `responses` on completion of input chan `payloads`.
This enables the ability to do fee payer, and other approaches while staying concurrent
func Example() { client := NewNodeClient() sender := NewEd25519Account() feePayer := NewEd25519Account() payloads := make(chan TransactionBuildPayload) responses := make(chan TransactionSubmissionResponse) signingFunc := func(rawTxn RawTransactionImpl) (*SignedTransaction, error) { switch rawTxn.(type) { case *RawTransaction: return nil, fmt.Errorf("only fee payer supported") case *RawTransactionWithData: rawTxnWithData := rawTxn.(*RawTransactionWithData) switch rawTxnWithData.Variant { case MultiAgentRawTransactionWithDataVariant: return nil, fmt.Errorf("multi agent not supported, please provide a fee payer function") case MultiAgentWithFeePayerRawTransactionWithDataVariant: rawTxnWithData.Sign(sender) txn, ok := rawTxnWithData.ToFeePayerTransaction() default: return nil, fmt.Errorf("unsupported rawTransactionWithData type") } default: return nil, fmt.Errorf("unsupported rawTransactionImpl type") } } // startup worker go client.BuildSignAndSubmitTransactionsWithSignFunction( sender, payloads, responses, signingFunc ) // Here add payloads, and wiating on resposnes }
func (*NodeClient) BuildTransaction ¶
func (rc *NodeClient) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error)
BuildTransaction builds a raw transaction for signing for a single signer
For MultiAgent and FeePayer transactions use NodeClient.BuildTransactionMultiAgent
Accepts options:
func (*NodeClient) BuildTransactionMultiAgent ¶ added in v0.2.0
func (rc *NodeClient) BuildTransactionMultiAgent(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxnImpl *RawTransactionWithData, err error)
BuildTransactionMultiAgent builds a raw transaction for signing with fee payer or multi-agent
For single signer transactions use NodeClient.BuildTransaction
Accepts options:
func (*NodeClient) BuildTransactions ¶ added in v0.4.0
func (rc *NodeClient) BuildTransactions(sender AccountAddress, payloads chan TransactionBuildPayload, responses chan TransactionBuildResponse, setSequenceNumber chan uint64, options ...any)
BuildTransactions start a goroutine to process TransactionPayload and spit out RawTransactionImpl.
func (*NodeClient) EstimateGasPrice ¶ added in v0.2.0
func (rc *NodeClient) EstimateGasPrice() (info EstimateGasInfo, err error)
EstimateGasPrice estimates the gas price given on-chain data TODO: add caching for some period of time
func (*NodeClient) GetBCS ¶
func (rc *NodeClient) GetBCS(getUrl string) (out []byte, err error)
GetBCS makes a GET request to the endpoint and parses the response into the given type with BCS
func (*NodeClient) GetChainId ¶
func (rc *NodeClient) GetChainId() (chainId uint8, err error)
GetChainId gets the chain ID of the network
func (*NodeClient) Info ¶
func (rc *NodeClient) Info() (info NodeInfo, err error)
Info gets general information about the blockchain
func (*NodeClient) NodeHealthCheck ¶ added in v0.5.0
func (rc *NodeClient) NodeHealthCheck(durationSecs ...uint64) (api.HealthCheckResponse, error)
NodeHealthCheck performs a health check on the node
Returns a HealthCheckResponse if successful, returns error if not.
func (*NodeClient) PollForTransaction ¶ added in v0.2.0
func (rc *NodeClient) PollForTransaction(hash string, options ...any) (*api.UserTransaction, error)
PollForTransaction waits up to 10 seconds for a transaction to be done, polling at 10Hz Accepts options PollPeriod and PollTimeout which should wrap time.Duration values. Not just a degenerate case of PollForTransactions, it may return additional information for the single transaction polled.
func (*NodeClient) PollForTransactions ¶
func (rc *NodeClient) PollForTransactions(txnHashes []string, options ...any) error
PollForTransactions waits up to 10 seconds for transactions to be done, polling at 10Hz Accepts options PollPeriod and PollTimeout which should wrap time.Duration values.
func (*NodeClient) RemoveHeader ¶ added in v0.6.0
func (rc *NodeClient) RemoveHeader(key string)
RemoveHeader removes the header from being automatically set all future requests.
client.RemoveHeader("Authorization")
func (*NodeClient) SetHeader ¶ added in v0.6.0
func (rc *NodeClient) SetHeader(key string, value string)
SetHeader sets the header for all future requests
client.SetHeader("Authorization", "Bearer abcde")
func (*NodeClient) SetTimeout ¶ added in v0.6.0
func (rc *NodeClient) SetTimeout(timeout time.Duration)
SetTimeout adjusts the HTTP client timeout
client.SetTimeout(5 * time.Millisecond)
func (*NodeClient) SimulateTransaction ¶ added in v0.4.0
func (rc *NodeClient) SimulateTransaction(rawTxn *RawTransaction, sender TransactionSigner, options ...any) (data []*api.UserTransaction, err error)
SimulateTransaction simulates a transaction
TODO: This needs to support RawTransactionWithData TODO: Support multikey simulation
func (*NodeClient) SubmitTransaction ¶
func (rc *NodeClient) SubmitTransaction(signedTxn *SignedTransaction) (data *api.SubmitTransactionResponse, err error)
SubmitTransaction submits a signed transaction to the network
func (*NodeClient) SubmitTransactions ¶ added in v0.4.0
func (rc *NodeClient) SubmitTransactions(requests chan TransactionSubmissionRequest, responses chan TransactionSubmissionResponse)
SubmitTransactions consumes signed transactions, submits to aptos-node, yields responses. closes output chan `responses` when input chan `signedTxns` is closed.
func (*NodeClient) TransactionByHash ¶
func (rc *NodeClient) TransactionByHash(txnHash string) (data *api.Transaction, err error)
TransactionByHash gets info on a transaction The transaction may be pending or recently committed. If the transaction is a api.PendingTransaction, then it is still in the mempool. If the transaction is any other type, it has been committed.
data, err := c.TransactionByHash("0xabcd") if err != nil { if httpErr, ok := err.(aptos.HttpError) { if httpErr.StatusCode == 404 { // if we're sure this has been submitted, assume it is still pending elsewhere in the mempool } } } else { if data["type"] == "pending_transaction" { // known to local mempool, but not committed yet } }
func (*NodeClient) TransactionByVersion ¶
func (rc *NodeClient) TransactionByVersion(version uint64) (data *api.CommittedTransaction, err error)
TransactionByVersion gets info on a transaction by version number The transaction will have been committed. The response will not be of the type api.PendingTransaction.
func (*NodeClient) Transactions ¶
func (rc *NodeClient) Transactions(start *uint64, limit *uint64) (data []*api.CommittedTransaction, err error)
Transactions Get recent transactions.
Arguments:
- start is a version number. Nil for most recent transactions.
- limit is a number of transactions to return. 'about a hundred' by default.
func (*NodeClient) View ¶
func (rc *NodeClient) View(payload *ViewPayload, ledgerVersion ...uint64) (data []any, err error)
View calls a view function on the blockchain and returns the return value of the function
func (*NodeClient) WaitForTransaction ¶
func (rc *NodeClient) WaitForTransaction(txnHash string, options ...any) (data *api.UserTransaction, err error)
WaitForTransaction does a long-GET for one transaction and wait for it to complete. Initially poll at 10 Hz for up to 1 second if node replies with 404 (wait for txn to propagate).
Optional arguments:
- PollPeriod: time.Duration, how often to poll for the transaction. Default 100ms.
- PollTimeout: time.Duration, how long to wait for the transaction. Default 10s.
type NodeInfo ¶
type NodeInfo struct { ChainId uint8 `json:"chain_id"` // ChainId is the chain ID of the network EpochStr string `json:"epoch"` // EpochStr is the current epoch of the network. On Mainnet, this is usually every 2 hours. LedgerTimestampStr string `json:"ledger_timestamp"` // LedgerTimestampStr is the timestamp the block was committed LedgerVersionStr string `json:"ledger_version"` // LedgerVersionStr is the newest transaction available on the full node OldestLedgerVersionStr string `json:"oldest_ledger_version"` // OldestLedgerVersionStr is the oldest ledger version not pruned on the full node NodeRole string `json:"node_role"` // NodeRole is the role of the node in the network BlockHeightStr string `json:"block_height"` // BlockHeightStr is the newest block available on the full node (by the time you call this there's already a new one!) OldestBlockHeightStr string `json:"oldest_block_height"` // OldestBlockHeightStr is the oldest block note pruned on the full node GitHash string `json:"git_hash"` // GitHash is the git hash of the node }
NodeInfo information retrieved about the current state of the blockchain on API requests
func (NodeInfo) BlockHeight ¶
BlockHeight the newest block available on the full node (by the time you call this there's already a new one!)
func (NodeInfo) Epoch ¶
Epoch the current epoch of the network. On Mainnet, this is usually every 2 hours.
func (NodeInfo) LedgerTimestamp ¶ added in v0.2.0
LedgerTimestamp is the timestamp the block was committed
func (NodeInfo) LedgerVersion ¶
LedgerVersion the newest transaction available on the full node
func (NodeInfo) OldestBlockHeight ¶
OldestBlockHeight the oldest block note pruned on the full node
func (NodeInfo) OldestLedgerVersion ¶
OldestLedgerVersion the oldest ledger version not pruned on the full node
type RawTransaction ¶
type RawTransaction struct { Sender AccountAddress SequenceNumber uint64 Payload TransactionPayload MaxGasAmount uint64 GasUnitPrice uint64 // ExpirationTimestampSeconds is seconds since Unix epoch ExpirationTimestampSeconds uint64 ChainId uint8 }
RawTransaction representation of a transaction's parts prior to signing Implements crypto.MessageSigner, crypto.Signer, bcs.Struct
func APTTransferTransaction ¶
func APTTransferTransaction(client *Client, sender TransactionSigner, dest AccountAddress, amount uint64, options ...any) (rawTxn *RawTransaction, err error)
APTTransferTransaction Move some APT from sender to dest, only for single signer Amount in Octas (10^-8 APT)
options may be: MaxGasAmount, GasUnitPrice, ExpirationSeconds, ValidUntil, SequenceNumber, ChainIdOption deprecated, please use the EntryFunction APIs
func (*RawTransaction) MarshalBCS ¶
func (txn *RawTransaction) MarshalBCS(ser *bcs.Serializer)
func (*RawTransaction) Sign ¶
func (txn *RawTransaction) Sign(signer crypto.Signer) (authenticator *crypto.AccountAuthenticator, err error)
func (*RawTransaction) SignedTransaction ¶ added in v0.2.0
func (txn *RawTransaction) SignedTransaction(sender crypto.Signer) (*SignedTransaction, error)
func (*RawTransaction) SignedTransactionWithAuthenticator ¶ added in v0.2.0
func (txn *RawTransaction) SignedTransactionWithAuthenticator(auth *crypto.AccountAuthenticator) (*SignedTransaction, error)
SignedTransactionWithAuthenticator signs the sender only signed transaction
func (*RawTransaction) SigningMessage ¶ added in v0.2.0
func (txn *RawTransaction) SigningMessage() (message []byte, err error)
SigningMessage generates the bytes needed to be signed by a signer
func (*RawTransaction) UnmarshalBCS ¶
func (txn *RawTransaction) UnmarshalBCS(des *bcs.Deserializer)
type RawTransactionImpl ¶ added in v0.2.0
type RawTransactionImpl interface { bcs.Struct // SigningMessage creates a raw signing message for the transaction // Note that this should only be used externally if signing transactions outside the SDK. Otherwise, use Sign. SigningMessage() (message []byte, err error) // Sign signs a transaction and returns the associated AccountAuthenticator, it will underneath sign the SigningMessage Sign(signer crypto.Signer) (*crypto.AccountAuthenticator, error) }
type RawTransactionWithData ¶ added in v0.2.0
type RawTransactionWithData struct { Variant RawTransactionWithDataVariant Inner RawTransactionWithDataImpl }
func (*RawTransactionWithData) MarshalBCS ¶ added in v0.2.0
func (txn *RawTransactionWithData) MarshalBCS(ser *bcs.Serializer)
func (*RawTransactionWithData) SetFeePayer ¶ added in v0.5.0
func (txn *RawTransactionWithData) SetFeePayer( feePayer AccountAddress, ) bool
func (*RawTransactionWithData) Sign ¶ added in v0.2.0
func (txn *RawTransactionWithData) Sign(signer crypto.Signer) (authenticator *crypto.AccountAuthenticator, err error)
func (*RawTransactionWithData) SigningMessage ¶ added in v0.2.0
func (txn *RawTransactionWithData) SigningMessage() (message []byte, err error)
func (*RawTransactionWithData) ToFeePayerSignedTransaction ¶ added in v0.2.0
func (txn *RawTransactionWithData) ToFeePayerSignedTransaction( sender *crypto.AccountAuthenticator, feePayerAuthenticator *crypto.AccountAuthenticator, additionalSigners []crypto.AccountAuthenticator, ) (*SignedTransaction, bool)
func (*RawTransactionWithData) ToMultiAgentSignedTransaction ¶ added in v0.2.0
func (txn *RawTransactionWithData) ToMultiAgentSignedTransaction( sender *crypto.AccountAuthenticator, additionalSigners []crypto.AccountAuthenticator, ) (*SignedTransaction, bool)
func (*RawTransactionWithData) UnmarshalBCS ¶ added in v0.2.0
func (txn *RawTransactionWithData) UnmarshalBCS(des *bcs.Deserializer)
type RawTransactionWithDataImpl ¶ added in v0.2.0
type RawTransactionWithDataVariant ¶ added in v0.2.0
type RawTransactionWithDataVariant uint32
const ( MultiAgentRawTransactionWithDataVariant RawTransactionWithDataVariant = 0 MultiAgentWithFeePayerRawTransactionWithDataVariant RawTransactionWithDataVariant = 1 )
type Script ¶
type Script struct { Code []byte // The compiled script bytes ArgTypes []TypeTag // The types of the arguments Args []ScriptArgument // The arguments }
Script A Move script as compiled code as a transaction
func (*Script) MarshalBCS ¶
func (s *Script) MarshalBCS(ser *bcs.Serializer)
func (*Script) PayloadType ¶ added in v0.2.0
func (s *Script) PayloadType() TransactionPayloadVariant
func (*Script) UnmarshalBCS ¶
func (s *Script) UnmarshalBCS(des *bcs.Deserializer)
type ScriptArgument ¶
type ScriptArgument struct { Variant ScriptArgumentVariant // The type of the argument Value any // The value of the argument }
ScriptArgument a Move script argument, which encodes its type with it
func (*ScriptArgument) MarshalBCS ¶
func (sa *ScriptArgument) MarshalBCS(ser *bcs.Serializer)
func (*ScriptArgument) UnmarshalBCS ¶
func (sa *ScriptArgument) UnmarshalBCS(des *bcs.Deserializer)
type ScriptArgumentVariant ¶
type ScriptArgumentVariant uint32
ScriptArgumentVariant the type of the script argument. If there isn't a value here, it is not supported.
Note that the only vector supported is vector<u8>
const ( ScriptArgumentU8 ScriptArgumentVariant = 0 // u8 type argument ScriptArgumentU64 ScriptArgumentVariant = 1 // u64 type argument ScriptArgumentU128 ScriptArgumentVariant = 2 // u128 type argument ScriptArgumentAddress ScriptArgumentVariant = 3 // address type argument ScriptArgumentU8Vector ScriptArgumentVariant = 4 // vector<u8> type argument ScriptArgumentBool ScriptArgumentVariant = 5 // bool type argument ScriptArgumentU16 ScriptArgumentVariant = 6 // u16 type argument ScriptArgumentU32 ScriptArgumentVariant = 7 // u32 type argument ScriptArgumentU256 ScriptArgumentVariant = 8 // u256 type argument )
type SequenceNumber ¶
type SequenceNumber uint64
SequenceNumber will set the sequence number for a transaction
type SequenceNumberTracker ¶ added in v0.4.0
func (*SequenceNumberTracker) Increment ¶ added in v0.4.0
func (snt *SequenceNumberTracker) Increment() uint64
func (*SequenceNumberTracker) Update ¶ added in v0.4.0
func (snt *SequenceNumberTracker) Update(next uint64) uint64
type SignedTransaction ¶
type SignedTransaction struct { Transaction *RawTransaction // The transaction here is always a [RawTransaction], the rest of the information is in the authenticator Authenticator *TransactionAuthenticator // The authenticator for a transaction (can't be be a standalone [crypto.AccountAuthenticator]) }
SignedTransaction a raw transaction plus its authenticator for a fully verifiable message
func (*SignedTransaction) Hash ¶ added in v0.2.0
func (txn *SignedTransaction) Hash() (string, error)
Hash takes the hash of the SignedTransaction
Note: At the moment, this assumes that the transaction is a UserTransaction
func (*SignedTransaction) MarshalBCS ¶
func (txn *SignedTransaction) MarshalBCS(ser *bcs.Serializer)
func (*SignedTransaction) UnmarshalBCS ¶
func (txn *SignedTransaction) UnmarshalBCS(des *bcs.Deserializer)
func (*SignedTransaction) Verify ¶
func (txn *SignedTransaction) Verify() error
Verify checks a signed transaction's signature
type SignedTransactionVariant ¶ added in v0.2.0
type SignedTransactionVariant uint8
SignedTransactionVariant is the variant for a signed transaction
const UserTransactionVariant SignedTransactionVariant = 0
UserTransactionVariant is the variant for a transaction submitted by a user. For now, we don't support any others, because they can't be submitted.
type SignerTag ¶ added in v0.2.0
type SignerTag struct{}
SignerTag represents the signer type in Move
func (*SignerTag) GetType ¶ added in v0.2.0
func (xt *SignerTag) GetType() TypeTagVariant
func (*SignerTag) MarshalBCS ¶ added in v0.2.0
func (xt *SignerTag) MarshalBCS(_ *bcs.Serializer)
func (*SignerTag) UnmarshalBCS ¶ added in v0.2.0
func (xt *SignerTag) UnmarshalBCS(_ *bcs.Deserializer)
type SingleSenderTransactionAuthenticator ¶ added in v0.2.0
type SingleSenderTransactionAuthenticator struct {
Sender *crypto.AccountAuthenticator
}
func (*SingleSenderTransactionAuthenticator) MarshalBCS ¶ added in v0.2.0
func (ea *SingleSenderTransactionAuthenticator) MarshalBCS(ser *bcs.Serializer)
func (*SingleSenderTransactionAuthenticator) UnmarshalBCS ¶ added in v0.2.0
func (ea *SingleSenderTransactionAuthenticator) UnmarshalBCS(des *bcs.Deserializer)
func (*SingleSenderTransactionAuthenticator) Verify ¶ added in v0.2.0
func (ea *SingleSenderTransactionAuthenticator) Verify(msg []byte) bool
type StructTag ¶
type StructTag struct { Address AccountAddress // Address is the address of the module Module string // Module is the name of the module Name string // Name is the name of the struct TypeParams []TypeTag // TypeParams are the TypeTags of the type parameters }
StructTag represents an on-chain struct of the form address::module::name<T1,T2,...> and each T is a TypeTag
func NewObjectTag ¶ added in v0.2.0
func NewObjectTag(inner TypeTagImpl) *StructTag
NewObjectTag creates a 0x1::object::Object TypeTag based on an inner type
func NewOptionTag ¶ added in v0.2.0
func NewOptionTag(inner TypeTagImpl) *StructTag
NewOptionTag creates a 0x1::option::Option TypeTag based on an inner type
func NewStringTag ¶ added in v0.2.0
func NewStringTag() *StructTag
NewStringTag creates a TypeTag for 0x1::string::String
func (*StructTag) GetType ¶
func (xt *StructTag) GetType() TypeTagVariant
func (*StructTag) MarshalBCS ¶
func (xt *StructTag) MarshalBCS(ser *bcs.Serializer)
func (*StructTag) String ¶
String outputs to the form address::module::name<type1, type2> e.g. 0x1::string::String or 0x42::my_mod::MultiType<u8,0x1::string::String>
func (*StructTag) UnmarshalBCS ¶
func (xt *StructTag) UnmarshalBCS(des *bcs.Deserializer)
type TransactionAuthenticator ¶ added in v0.2.0
type TransactionAuthenticator struct { Variant TransactionAuthenticatorVariant Auth TransactionAuthenticatorImpl }
TransactionAuthenticator is used for authorizing a transaction. This differs from crypto.AccountAuthenticator because it handles constructs like FeePayer and MultiAgent. Some keys can't stand on their own as TransactionAuthenticators. Implements TransactionAuthenticatorImpl, bcs.Struct
func NewTransactionAuthenticator ¶ added in v0.4.0
func NewTransactionAuthenticator(auth *crypto.AccountAuthenticator) (*TransactionAuthenticator, error)
func (*TransactionAuthenticator) MarshalBCS ¶ added in v0.2.0
func (ea *TransactionAuthenticator) MarshalBCS(ser *bcs.Serializer)
func (*TransactionAuthenticator) UnmarshalBCS ¶ added in v0.2.0
func (ea *TransactionAuthenticator) UnmarshalBCS(des *bcs.Deserializer)
func (*TransactionAuthenticator) Verify ¶ added in v0.2.0
func (ea *TransactionAuthenticator) Verify(msg []byte) bool
type TransactionAuthenticatorImpl ¶ added in v0.2.0
type TransactionAuthenticatorVariant ¶ added in v0.2.0
type TransactionAuthenticatorVariant uint8
const ( TransactionAuthenticatorEd25519 TransactionAuthenticatorVariant = 0 TransactionAuthenticatorMultiEd25519 TransactionAuthenticatorVariant = 1 TransactionAuthenticatorMultiAgent TransactionAuthenticatorVariant = 2 TransactionAuthenticatorFeePayer TransactionAuthenticatorVariant = 3 TransactionAuthenticatorSingleSender TransactionAuthenticatorVariant = 4 )
type TransactionBuildPayload ¶ added in v0.6.0
type TransactionBuildPayload struct { Id uint64 Type TransactionSubmissionType Inner TransactionPayload // The actual transaction payload Options []any // This is a placeholder to allow future optional arguments }
type TransactionBuildResponse ¶ added in v0.4.0
type TransactionBuildResponse struct { Id uint64 Response RawTransactionImpl Err error }
type TransactionPayload ¶
type TransactionPayload struct {
Payload TransactionPayloadImpl
}
TransactionPayload the actual instructions of which functions to call on chain
func PublishPackagePayloadFromJsonFile ¶ added in v0.2.0
func PublishPackagePayloadFromJsonFile(metadata []byte, bytecode [][]byte) (*TransactionPayload, error)
PublishPackagePayloadFromJsonFile publishes code created with the Aptos CLI to publish with it. The Aptos CLI can generate the associated file with the following CLI command:
aptos move build-publish-payload
metadata must be the BCS encoded metadata from the compiler, and bytecode must be the BCS encoded bytecode from the compiler. bytecode must be ordered in the same order out of the compiler, or it will fail on publishing.
func (*TransactionPayload) MarshalBCS ¶
func (txn *TransactionPayload) MarshalBCS(ser *bcs.Serializer)
func (*TransactionPayload) UnmarshalBCS ¶
func (txn *TransactionPayload) UnmarshalBCS(des *bcs.Deserializer)
type TransactionPayloadImpl ¶ added in v0.2.0
type TransactionPayloadImpl interface { bcs.Struct PayloadType() TransactionPayloadVariant // This is specifically to ensure that wrong types don't end up here }
type TransactionPayloadVariant ¶ added in v0.2.0
type TransactionPayloadVariant uint32
const ( TransactionPayloadVariantScript TransactionPayloadVariant = 0 TransactionPayloadVariantModuleBundle TransactionPayloadVariant = 1 // Deprecated TransactionPayloadVariantEntryFunction TransactionPayloadVariant = 2 TransactionPayloadVariantMultisig TransactionPayloadVariant = 3 )
type TransactionSigner ¶ added in v0.2.0
type TransactionSigner interface { crypto.Signer // AccountAddress returns the address of the signer, this may differ from the AuthKey derived from the inner signer AccountAddress() AccountAddress }
TransactionSigner is a generic interface for a way to sign transactions. The default implementation is Account
Note that AccountAddress is needed to be the correct on-chain value for proper signing. This may differ from the AuthKey provided by the crypto.Signer
type TransactionSubmissionRequest ¶ added in v0.6.0
type TransactionSubmissionRequest struct { Id uint64 SignedTxn *SignedTransaction }
type TransactionSubmissionResponse ¶ added in v0.4.0
type TransactionSubmissionResponse struct { Id uint64 Response *api.SubmitTransactionResponse Err error }
type TransactionSubmissionType ¶ added in v0.4.0
type TransactionSubmissionType uint8
TransactionSubmissionType is the counter for an enum
const ( // TransactionSubmissionTypeSingle represents a single signer transaction, no multi-agent and no-fee payer TransactionSubmissionTypeSingle TransactionSubmissionType = iota // TransactionSubmissionTypeMultiAgent represents a multi-agent or fee payer transaction TransactionSubmissionTypeMultiAgent TransactionSubmissionType = iota )
type TypeTag ¶
type TypeTag struct {
Value TypeTagImpl
}
TypeTag is a wrapper around a TypeTagImpl e.g. BoolTag or U8Tag for the purpose of serialization and deserialization Implements:
func NewTypeTag ¶
func NewTypeTag(inner TypeTagImpl) TypeTag
NewTypeTag wraps a TypeTagImpl in a TypeTag
func (*TypeTag) MarshalBCS ¶
func (tt *TypeTag) MarshalBCS(ser *bcs.Serializer)
MarshalBCS serializes the TypeTag to bytes
Implements:
func (*TypeTag) UnmarshalBCS ¶
func (tt *TypeTag) UnmarshalBCS(des *bcs.Deserializer)
UnmarshalBCS deserializes the TypeTag from bytes
Implements:
type TypeTagImpl ¶
type TypeTagImpl interface { bcs.Struct // GetType returns the TypeTagVariant for this [TypeTag] GetType() TypeTagVariant // String returns the canonical Move string representation of this [TypeTag] String() string }
TypeTagImpl is an interface describing all the different types of TypeTag. Unfortunately because of how serialization works, a wrapper TypeTag struct is needed to handle the differentiation between types
type TypeTagVariant ¶ added in v0.2.0
type TypeTagVariant uint32
TypeTagVariant is an enum representing the different types of TypeTag
const ( TypeTagBool TypeTagVariant = 0 // Represents the bool type in Move BoolTag TypeTagU8 TypeTagVariant = 1 // Represents the u8 type in Move U8Tag TypeTagU64 TypeTagVariant = 2 // Represents the u64 type in Move U64Tag TypeTagU128 TypeTagVariant = 3 // Represents the u128 type in Move U128Tag TypeTagAddress TypeTagVariant = 4 // Represents the address type in Move AddressTag TypeTagSigner TypeTagVariant = 5 // Represents the signer type in Move SignerTag TypeTagVector TypeTagVariant = 6 // Represents the vector type in Move VectorTag TypeTagStruct TypeTagVariant = 7 // Represents the struct type in Move StructTag TypeTagU16 TypeTagVariant = 8 // Represents the u16 type in Move U16Tag TypeTagU32 TypeTagVariant = 9 // Represents the u32 type in Move U32Tag TypeTagU256 TypeTagVariant = 10 // Represents the u256 type in Move U256Tag )
type U128Tag ¶ added in v0.2.0
type U128Tag struct{}
U128Tag represents the u128 type in Move
func (*U128Tag) GetType ¶ added in v0.2.0
func (xt *U128Tag) GetType() TypeTagVariant
func (*U128Tag) MarshalBCS ¶ added in v0.2.0
func (xt *U128Tag) MarshalBCS(_ *bcs.Serializer)
func (*U128Tag) UnmarshalBCS ¶ added in v0.2.0
func (xt *U128Tag) UnmarshalBCS(_ *bcs.Deserializer)
type U16Tag ¶
type U16Tag struct{}
U16Tag represents the u16 type in Move
func (*U16Tag) GetType ¶
func (xt *U16Tag) GetType() TypeTagVariant
func (*U16Tag) MarshalBCS ¶
func (xt *U16Tag) MarshalBCS(_ *bcs.Serializer)
func (*U16Tag) UnmarshalBCS ¶
func (xt *U16Tag) UnmarshalBCS(_ *bcs.Deserializer)
type U256Tag ¶ added in v0.2.0
type U256Tag struct{}
U256Tag represents the u256 type in Move
func (*U256Tag) GetType ¶ added in v0.2.0
func (xt *U256Tag) GetType() TypeTagVariant
func (*U256Tag) MarshalBCS ¶ added in v0.2.0
func (xt *U256Tag) MarshalBCS(_ *bcs.Serializer)
func (*U256Tag) UnmarshalBCS ¶ added in v0.2.0
func (xt *U256Tag) UnmarshalBCS(_ *bcs.Deserializer)
type U32Tag ¶
type U32Tag struct{}
U32Tag represents the u32 type in Move
func (*U32Tag) GetType ¶
func (xt *U32Tag) GetType() TypeTagVariant
func (*U32Tag) MarshalBCS ¶
func (xt *U32Tag) MarshalBCS(_ *bcs.Serializer)
func (*U32Tag) UnmarshalBCS ¶
func (xt *U32Tag) UnmarshalBCS(_ *bcs.Deserializer)
type U64Tag ¶
type U64Tag struct{}
U64Tag represents the u64 type in Move
func (*U64Tag) GetType ¶
func (xt *U64Tag) GetType() TypeTagVariant
func (*U64Tag) MarshalBCS ¶
func (xt *U64Tag) MarshalBCS(_ *bcs.Serializer)
func (*U64Tag) UnmarshalBCS ¶
func (xt *U64Tag) UnmarshalBCS(_ *bcs.Deserializer)
type U8Tag ¶
type U8Tag struct{}
U8Tag represents the u8 type in Move
func (*U8Tag) GetType ¶
func (xt *U8Tag) GetType() TypeTagVariant
func (*U8Tag) MarshalBCS ¶
func (xt *U8Tag) MarshalBCS(_ *bcs.Serializer)
func (*U8Tag) UnmarshalBCS ¶
func (xt *U8Tag) UnmarshalBCS(_ *bcs.Deserializer)
type VectorTag ¶ added in v0.2.0
type VectorTag struct {
TypeParam TypeTag // TypeParam is the type of the elements in the vector
}
VectorTag represents the vector<T> type in Move, where T is another TypeTag
func NewVectorTag ¶ added in v0.2.0
func NewVectorTag(inner TypeTagImpl) *VectorTag
NewVectorTag creates a TypeTag for vector<inner>
func (*VectorTag) GetType ¶ added in v0.2.0
func (xt *VectorTag) GetType() TypeTagVariant
func (*VectorTag) MarshalBCS ¶ added in v0.2.0
func (xt *VectorTag) MarshalBCS(ser *bcs.Serializer)
func (*VectorTag) UnmarshalBCS ¶ added in v0.2.0
func (xt *VectorTag) UnmarshalBCS(des *bcs.Deserializer)
type ViewPayload ¶
type ViewPayload struct { Module ModuleId // ModuleId of the View function e.g. 0x1::coin Function string // Name of the View function e.g. balance ArgTypes []TypeTag // TypeTags of the type arguments Args [][]byte // Arguments to the function encoded in BCS }
ViewPayload is a payload for a view function
func (*ViewPayload) MarshalBCS ¶
func (vp *ViewPayload) MarshalBCS(ser *bcs.Serializer)
Source Files ¶
- account.go
- accountInfo.go
- accountResourceInfo.go
- accountResourceRecord.go
- client.go
- client_util.go
- code.go
- coinPayloads.go
- commonPayloads.go
- doc.go
- estimateGasInfo.go
- faucet.go
- fungible_asset_client.go
- http.go
- indexerClient.go
- moduleId.go
- multisig.go
- nodeClient.go
- nodeInfo.go
- rawTransaction.go
- script.go
- signedTransaction.go
- transactionAuthenticator.go
- transactionPayload.go
- transactionSubmission.go
- typetag.go
- util.go
Directories ¶
Path | Synopsis |
---|---|
Package api represents all types associated with the Aptos REST API.
|
Package api represents all types associated with the Aptos REST API. |
Package bcs implements Binary Canonical Serialization [BCS].
|
Package bcs implements Binary Canonical Serialization [BCS]. |
Package crypto handles all cryptographic types and operations associated with Aptos.
|
Package crypto handles all cryptographic types and operations associated with Aptos. |
Package examples is a collection of examples for the Aptos Go SDK.
|
Package examples is a collection of examples for the Aptos Go SDK. |
alternative_signing
alternative_signing is an example of how to create an alternative signer for the SDK, if you prefer a different library
|
alternative_signing is an example of how to create an alternative signer for the SDK, if you prefer a different library |
external_signing
external_signing is an example of how to create an external signer for the SDK, if you have something like cold storage signing
|
external_signing is an example of how to create an external signer for the SDK, if you have something like cold storage signing |
fungible_asset
fungible_asset is an example of how to create and transfer fungible assets
|
fungible_asset is an example of how to create and transfer fungible assets |
onchain_multisig
onchain_multisig is an example of how to create a multisig account and perform transactions with it.
|
onchain_multisig is an example of how to create a multisig account and perform transactions with it. |
performance_transaction
performance_transaction shows how to improve performance of the transaction submission of a single transaction
|
performance_transaction shows how to improve performance of the transaction submission of a single transaction |
sending_concurrent_transactions
sending_concurrent_transactions shows how to submit transactions serially or concurrently on a single account
|
sending_concurrent_transactions shows how to submit transactions serially or concurrently on a single account |
sponsored_transaction
sponsored_transaction is an example of how to make a sponsored transaction in Aptos.
|
sponsored_transaction is an example of how to make a sponsored transaction in Aptos. |
transfer_coin
transfer_coin is an example of how to make a coin transfer transaction in the simplest possible way
|
transfer_coin is an example of how to make a coin transfer transaction in the simplest possible way |
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. |