@aptos-labs/ts-sdk 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/browser/index.global.js +410 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/cjs/index.d.ts +4965 -0
- package/dist/cjs/index.js +4762 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.ts +4965 -0
- package/dist/esm/index.mjs +4645 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +1247 -0
- package/dist/types/index.js +151 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +79 -0
- package/src/api/account.ts +360 -0
- package/src/api/aptos.ts +103 -0
- package/src/api/aptosConfig.ts +77 -0
- package/src/api/coin.ts +39 -0
- package/src/api/digitalAsset.ts +192 -0
- package/src/api/event.ts +78 -0
- package/src/api/faucet.ts +30 -0
- package/src/api/fungibleAsset.ts +82 -0
- package/src/api/general.ts +188 -0
- package/src/api/index.ts +5 -0
- package/src/api/staking.ts +58 -0
- package/src/api/transaction.ts +135 -0
- package/src/api/transactionSubmission.ts +168 -0
- package/src/bcs/consts.ts +12 -0
- package/src/bcs/deserializer.ts +248 -0
- package/src/bcs/index.ts +9 -0
- package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
- package/src/bcs/serializable/fixedBytes.ts +65 -0
- package/src/bcs/serializable/movePrimitives.ts +211 -0
- package/src/bcs/serializable/moveStructs.ts +462 -0
- package/src/bcs/serializer.ts +353 -0
- package/src/client/core.ts +106 -0
- package/src/client/get.ts +109 -0
- package/src/client/index.ts +7 -0
- package/src/client/post.ts +90 -0
- package/src/client/types.ts +58 -0
- package/src/core/account.ts +180 -0
- package/src/core/accountAddress.ts +407 -0
- package/src/core/authenticationKey.ts +102 -0
- package/src/core/common.ts +40 -0
- package/src/core/crypto/asymmetricCrypto.ts +77 -0
- package/src/core/crypto/ed25519.ts +224 -0
- package/src/core/crypto/index.ts +7 -0
- package/src/core/crypto/multiEd25519.ts +251 -0
- package/src/core/crypto/secp256k1.ts +227 -0
- package/src/core/hex.ts +177 -0
- package/src/core/index.ts +9 -0
- package/src/index.ts +12 -0
- package/src/internal/account.ts +484 -0
- package/src/internal/coin.ts +32 -0
- package/src/internal/digitalAsset.ts +302 -0
- package/src/internal/event.ts +88 -0
- package/src/internal/faucet.ts +41 -0
- package/src/internal/fungibleAsset.ts +114 -0
- package/src/internal/general.ts +160 -0
- package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
- package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
- package/src/internal/queries/getAccountCoinCount.graphql +7 -0
- package/src/internal/queries/getAccountCoinsData.graphql +32 -0
- package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
- package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
- package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
- package/src/internal/queries/getAccountTokensCount.graphql +7 -0
- package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
- package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
- package/src/internal/queries/getCollectionData.graphql +20 -0
- package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
- package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
- package/src/internal/queries/getEvents.graphql +12 -0
- package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
- package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
- package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
- package/src/internal/queries/getProcessorStatus.graphql +7 -0
- package/src/internal/queries/getTokenActivity.graphql +11 -0
- package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
- package/src/internal/queries/getTokenData.graphql +38 -0
- package/src/internal/staking.ts +68 -0
- package/src/internal/transaction.ts +245 -0
- package/src/internal/transactionSubmission.ts +162 -0
- package/src/transactions/authenticator/account.ts +121 -0
- package/src/transactions/authenticator/transaction.ts +222 -0
- package/src/transactions/instances/chainId.ts +26 -0
- package/src/transactions/instances/identifier.ts +28 -0
- package/src/transactions/instances/index.ts +9 -0
- package/src/transactions/instances/moduleId.ts +53 -0
- package/src/transactions/instances/rawTransaction.ts +199 -0
- package/src/transactions/instances/signedTransaction.ts +43 -0
- package/src/transactions/instances/transactionArgument.ts +37 -0
- package/src/transactions/instances/transactionPayload.ts +407 -0
- package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
- package/src/transactions/typeTag/typeTag.ts +487 -0
- package/src/transactions/types.ts +262 -0
- package/src/types/codegen.yaml +33 -0
- package/src/types/generated/operations.ts +623 -0
- package/src/types/generated/queries.ts +737 -0
- package/src/types/generated/types.ts +10387 -0
- package/src/types/index.ts +944 -0
- package/src/types/indexer.ts +93 -0
- package/src/utils/apiEndpoints.ts +36 -0
- package/src/utils/const.ts +51 -0
- package/src/utils/hdKey.ts +113 -0
- package/src/utils/helpers.ts +12 -0
- package/src/utils/memoize.ts +68 -0
- package/src/version.ts +9 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import {
|
|
6
|
+
getBlockByHeight,
|
|
7
|
+
getBlockByVersion,
|
|
8
|
+
getChainTopUserTransactions,
|
|
9
|
+
getIndexerLastSuccessVersion,
|
|
10
|
+
getLedgerInfo,
|
|
11
|
+
getTableItem,
|
|
12
|
+
queryIndexer,
|
|
13
|
+
view,
|
|
14
|
+
} from "../internal/general";
|
|
15
|
+
import {
|
|
16
|
+
AnyNumber,
|
|
17
|
+
Block,
|
|
18
|
+
GetChainTopUserTransactionsResponse,
|
|
19
|
+
GraphqlQuery,
|
|
20
|
+
LedgerInfo,
|
|
21
|
+
LedgerVersion,
|
|
22
|
+
MoveValue,
|
|
23
|
+
TableItemRequest,
|
|
24
|
+
ViewRequestData,
|
|
25
|
+
} from "../types";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A class to query all `General` Aptos related queries
|
|
29
|
+
*/
|
|
30
|
+
export class General {
|
|
31
|
+
readonly config: AptosConfig;
|
|
32
|
+
|
|
33
|
+
constructor(config: AptosConfig) {
|
|
34
|
+
this.config = config;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Queries for the Aptos ledger info
|
|
39
|
+
*
|
|
40
|
+
* @returns Aptos Ledger Info
|
|
41
|
+
*
|
|
42
|
+
* @example An example of the returned data
|
|
43
|
+
* ```
|
|
44
|
+
* {
|
|
45
|
+
* "chain_id": 4,
|
|
46
|
+
* "epoch": "8",
|
|
47
|
+
* "ledger_version": "714",
|
|
48
|
+
* "oldest_ledger_version": "0",
|
|
49
|
+
* "ledger_timestamp": "1694695496521775",
|
|
50
|
+
* "node_role": "validator",
|
|
51
|
+
* "oldest_block_height": "0",
|
|
52
|
+
* "block_height": "359",
|
|
53
|
+
* "git_hash": "c82193f36f4e185fed9f68c4ad21f6c6dd390c6e"
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async getLedgerInfo(): Promise<LedgerInfo> {
|
|
58
|
+
return getLedgerInfo({ aptosConfig: this.config });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Queries for the chain id
|
|
63
|
+
*
|
|
64
|
+
* @returns The chain id
|
|
65
|
+
*/
|
|
66
|
+
async getChainId(): Promise<number> {
|
|
67
|
+
const result = await this.getLedgerInfo();
|
|
68
|
+
return result.chain_id;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Queries for block by transaction version
|
|
73
|
+
*
|
|
74
|
+
* @param args.ledgerVersion Ledger version to lookup block information for
|
|
75
|
+
* @param args.options.withTransactions If set to true, include all transactions in the block
|
|
76
|
+
*
|
|
77
|
+
* @returns Block information with optional transactions
|
|
78
|
+
*/
|
|
79
|
+
async getBlockByVersion(args: {
|
|
80
|
+
ledgerVersion: AnyNumber;
|
|
81
|
+
options?: { withTransactions?: boolean };
|
|
82
|
+
}): Promise<Block> {
|
|
83
|
+
return getBlockByVersion({
|
|
84
|
+
aptosConfig: this.config,
|
|
85
|
+
...args,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get block by block height
|
|
91
|
+
*
|
|
92
|
+
* @param args.blockHeight Block height to lookup. Starts at 0
|
|
93
|
+
* @param args.options.withTransactions If set to true, include all transactions in the block
|
|
94
|
+
*
|
|
95
|
+
* @returns Block with optional transactions
|
|
96
|
+
*/
|
|
97
|
+
async getBlockByHeight(args: { blockHeight: AnyNumber; options?: { withTransactions?: boolean } }): Promise<Block> {
|
|
98
|
+
return getBlockByHeight({ aptosConfig: this.config, ...args });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Queries for a table item for a table identified by the handle and the key for the item.
|
|
103
|
+
* Key and value types need to be passed in to help with key serialization and value deserialization.
|
|
104
|
+
* @param args.handle A pointer to where that table is stored
|
|
105
|
+
* @param args.data Object that describes table item
|
|
106
|
+
* @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
|
|
107
|
+
*
|
|
108
|
+
* @example https://fullnode.devnet.aptoslabs.com/v1/accounts/0x1/resource/0x1::coin::CoinInfo%3C0x1::aptos_coin::AptosCoin%3E
|
|
109
|
+
* {
|
|
110
|
+
* data.key_type = "address" // Move type of table key
|
|
111
|
+
* data.value_type = "u128" // Move type of table value
|
|
112
|
+
* data.key = "0x619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935" // Value of table key
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* @returns Table item value rendered in JSON
|
|
116
|
+
*/
|
|
117
|
+
async getTableItem(args: { handle: string; data: TableItemRequest; options?: LedgerVersion }): Promise<any> {
|
|
118
|
+
return getTableItem({ aptosConfig: this.config, ...args });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Queries for a Move view function
|
|
123
|
+
* @param args.payload Payload for the view function
|
|
124
|
+
* @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version
|
|
125
|
+
* @example
|
|
126
|
+
* `
|
|
127
|
+
* const payload: ViewRequest = {
|
|
128
|
+
* function: "0x1::coin::balance",
|
|
129
|
+
* type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
|
130
|
+
* arguments: [accountAddress],
|
|
131
|
+
* };
|
|
132
|
+
* `
|
|
133
|
+
*
|
|
134
|
+
* @returns an array of Move values
|
|
135
|
+
*/
|
|
136
|
+
async view(args: { payload: ViewRequestData; options?: LedgerVersion }): Promise<Array<MoveValue>> {
|
|
137
|
+
return view({ aptosConfig: this.config, ...args });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Queries top user transactions
|
|
142
|
+
*
|
|
143
|
+
* @param args.limit The number of transactions to return
|
|
144
|
+
* @returns GetChainTopUserTransactionsResponse
|
|
145
|
+
*/
|
|
146
|
+
async getChainTopUserTransactions(args: { limit: number }): Promise<GetChainTopUserTransactionsResponse> {
|
|
147
|
+
return getChainTopUserTransactions({
|
|
148
|
+
aptosConfig: this.config,
|
|
149
|
+
...args,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A generic function for retrieving data from Aptos Indexer.
|
|
155
|
+
* For more detailed queries specification see
|
|
156
|
+
* {@link https://cloud.hasura.io/public/graphiql?endpoint=https://indexer.mainnet.aptoslabs.com/v1/graphql}
|
|
157
|
+
*
|
|
158
|
+
* @param args.query.query A GraphQL query
|
|
159
|
+
* @param args.query.variables The variables for the query
|
|
160
|
+
* @example
|
|
161
|
+
* ```
|
|
162
|
+
* {
|
|
163
|
+
* query: `query MyQuery {
|
|
164
|
+
ledger_infos {
|
|
165
|
+
chain_id
|
|
166
|
+
}
|
|
167
|
+
}`;
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @return The provided T type
|
|
172
|
+
*/
|
|
173
|
+
async queryIndexer<T>(args: { query: GraphqlQuery }): Promise<T> {
|
|
174
|
+
return queryIndexer<T>({
|
|
175
|
+
aptosConfig: this.config,
|
|
176
|
+
...args,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Queries for the last successful indexer version
|
|
182
|
+
*
|
|
183
|
+
* This is useful to tell what ledger version the indexer is updated to, as it can be behind the full nodes.
|
|
184
|
+
*/
|
|
185
|
+
async getIndexerLastSuccessVersion(): Promise<number> {
|
|
186
|
+
return getIndexerLastSuccessVersion({ aptosConfig: this.config });
|
|
187
|
+
}
|
|
188
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import {
|
|
6
|
+
getDelegatedStakingActivities,
|
|
7
|
+
getNumberOfDelegators,
|
|
8
|
+
getNumberOfDelegatorsForAllPools,
|
|
9
|
+
} from "../internal/staking";
|
|
10
|
+
import { GetDelegatedStakingActivitiesResponse, GetNumberOfDelegatorsResponse, HexInput, OrderBy } from "../types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A class to query all `Staking` related queries on Aptos.
|
|
14
|
+
*/
|
|
15
|
+
export class Staking {
|
|
16
|
+
readonly config: AptosConfig;
|
|
17
|
+
|
|
18
|
+
constructor(config: AptosConfig) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Queries current number of delegators in a pool. Throws an error if the pool is not found.
|
|
24
|
+
*
|
|
25
|
+
* @param args.poolAddress Pool address
|
|
26
|
+
* @returns The number of delegators for the given pool
|
|
27
|
+
*/
|
|
28
|
+
async getNumberOfDelegators(args: { poolAddress: HexInput }): Promise<number> {
|
|
29
|
+
return getNumberOfDelegators({ aptosConfig: this.config, ...args });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Queries current number of delegators in a pool. Throws an error if the pool is not found.
|
|
34
|
+
*
|
|
35
|
+
* @returns GetNumberOfDelegatorsForAllPoolsResponse response type
|
|
36
|
+
*/
|
|
37
|
+
async getNumberOfDelegatorsForAllPools(args?: {
|
|
38
|
+
options?: {
|
|
39
|
+
orderBy?: OrderBy<GetNumberOfDelegatorsResponse[0]>;
|
|
40
|
+
};
|
|
41
|
+
}): Promise<GetNumberOfDelegatorsResponse> {
|
|
42
|
+
return getNumberOfDelegatorsForAllPools({ aptosConfig: this.config, ...args });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Queries delegated staking activities
|
|
47
|
+
*
|
|
48
|
+
* @param args.delegatorAddress Delegator address
|
|
49
|
+
* @param args.poolAddress Pool address
|
|
50
|
+
* @returns GetDelegatedStakingActivitiesResponse response type
|
|
51
|
+
*/
|
|
52
|
+
async getDelegatedStakingActivities(args: {
|
|
53
|
+
delegatorAddress: HexInput;
|
|
54
|
+
poolAddress: HexInput;
|
|
55
|
+
}): Promise<GetDelegatedStakingActivitiesResponse> {
|
|
56
|
+
return getDelegatedStakingActivities({ aptosConfig: this.config, ...args });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import {
|
|
6
|
+
getGasPriceEstimation,
|
|
7
|
+
getTransactionByHash,
|
|
8
|
+
getTransactionByVersion,
|
|
9
|
+
getTransactions,
|
|
10
|
+
isTransactionPending,
|
|
11
|
+
waitForTransaction,
|
|
12
|
+
} from "../internal/transaction";
|
|
13
|
+
import { AnyNumber, GasEstimation, HexInput, PaginationArgs, TransactionResponse } from "../types";
|
|
14
|
+
|
|
15
|
+
export class Transaction {
|
|
16
|
+
readonly config: AptosConfig;
|
|
17
|
+
|
|
18
|
+
constructor(config: AptosConfig) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Queries on-chain transactions. This function will not return pending
|
|
24
|
+
* transactions. For that, use `getTransactionsByHash`.
|
|
25
|
+
*
|
|
26
|
+
* @param args.options.offset The number transaction to start with
|
|
27
|
+
* @param args.options.limit Number of results to return
|
|
28
|
+
*
|
|
29
|
+
* @returns Array of on-chain transactions
|
|
30
|
+
*/
|
|
31
|
+
async getTransactions(args?: { options?: PaginationArgs }): Promise<TransactionResponse[]> {
|
|
32
|
+
return getTransactions({
|
|
33
|
+
aptosConfig: this.config,
|
|
34
|
+
...args,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Queries on-chain transaction by version. This function will not return pending transactions.
|
|
40
|
+
*
|
|
41
|
+
* @param args.ledgerVersion - Transaction version is an unsigned 64-bit number.
|
|
42
|
+
* @returns On-chain transaction. Only on-chain transactions have versions, so this
|
|
43
|
+
* function cannot be used to query pending transactions.
|
|
44
|
+
*/
|
|
45
|
+
async getTransactionByVersion(args: { ledgerVersion: AnyNumber }): Promise<TransactionResponse> {
|
|
46
|
+
return getTransactionByVersion({
|
|
47
|
+
aptosConfig: this.config,
|
|
48
|
+
...args,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Queries on-chain transaction by transaction hash. This function will return pending transactions.
|
|
54
|
+
* @param args.transactionHash - Transaction hash should be hex-encoded bytes string with 0x prefix.
|
|
55
|
+
* @returns Transaction from mempool (pending) or on-chain (committed) transaction
|
|
56
|
+
*/
|
|
57
|
+
async getTransactionByHash(args: { transactionHash: HexInput }): Promise<TransactionResponse> {
|
|
58
|
+
return getTransactionByHash({
|
|
59
|
+
aptosConfig: this.config,
|
|
60
|
+
...args,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Defines if specified transaction is currently in pending state
|
|
66
|
+
*
|
|
67
|
+
* To create a transaction hash:
|
|
68
|
+
*
|
|
69
|
+
* 1. Create a hash message from the bytes: "Aptos::Transaction" bytes + the BCS-serialized Transaction bytes.
|
|
70
|
+
* 2. Apply hash algorithm SHA3-256 to the hash message bytes.
|
|
71
|
+
* 3. Hex-encode the hash bytes with 0x prefix.
|
|
72
|
+
*
|
|
73
|
+
* @param args.transactionHash A hash of transaction
|
|
74
|
+
* @returns `true` if transaction is in pending state and `false` otherwise
|
|
75
|
+
*/
|
|
76
|
+
async isPendingTransaction(args: { transactionHash: HexInput }): Promise<boolean> {
|
|
77
|
+
return isTransactionPending({
|
|
78
|
+
aptosConfig: this.config,
|
|
79
|
+
...args,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Waits for a transaction to move past the pending state.
|
|
85
|
+
*
|
|
86
|
+
* There are 4 cases.
|
|
87
|
+
* 1. Transaction is successfully processed and committed to the chain.
|
|
88
|
+
* - The function will resolve with the transaction response from the API.
|
|
89
|
+
* 2. Transaction is rejected for some reason, and is therefore not committed to the blockchain.
|
|
90
|
+
* - The function will throw an AptosApiError with an HTTP status code indicating some problem with the request.
|
|
91
|
+
* 3. Transaction is committed but execution failed, meaning no changes were
|
|
92
|
+
* written to the blockchain state.
|
|
93
|
+
* - If `checkSuccess` is true, the function will throw a FailedTransactionError
|
|
94
|
+
* If `checkSuccess` is false, the function will resolve with the transaction response where the `success` field is false.
|
|
95
|
+
* 4. Transaction does not move past the pending state within `args.options.timeoutSecs` seconds.
|
|
96
|
+
* - The function will throw a WaitForTransactionError
|
|
97
|
+
*
|
|
98
|
+
*
|
|
99
|
+
* @param args.transactionHash The hash of a transaction previously submitted to the blockchain.
|
|
100
|
+
* @param args.options.timeoutSecs Timeout in seconds. Defaults to 20 seconds.
|
|
101
|
+
* @param args.options.checkSuccess A boolean which controls whether the function will error if the transaction failed.
|
|
102
|
+
* Defaults to true. See case 3 above.
|
|
103
|
+
* @returns The transaction on-chain. See above for more details.
|
|
104
|
+
*/
|
|
105
|
+
async waitForTransaction(args: {
|
|
106
|
+
transactionHash: HexInput;
|
|
107
|
+
options?: { timeoutSecs?: number; checkSuccess?: boolean };
|
|
108
|
+
}): Promise<TransactionResponse> {
|
|
109
|
+
return waitForTransaction({
|
|
110
|
+
aptosConfig: this.config,
|
|
111
|
+
...args,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Gives an estimate of the gas unit price required to get a
|
|
117
|
+
* transaction on chain in a reasonable amount of time.
|
|
118
|
+
* For more information {@link https://fullnode.mainnet.aptoslabs.com/v1/spec#/operations/estimate_gas_price}
|
|
119
|
+
*
|
|
120
|
+
* @returns Object holding the outputs of the estimate gas API
|
|
121
|
+
* @example
|
|
122
|
+
* ```
|
|
123
|
+
* {
|
|
124
|
+
* gas_estimate: number;
|
|
125
|
+
* deprioritized_gas_estimate?: number;
|
|
126
|
+
* prioritized_gas_estimate?: number;
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async getGasPriceEstimation(): Promise<GasEstimation> {
|
|
131
|
+
return getGasPriceEstimation({
|
|
132
|
+
aptosConfig: this.config,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import { Account } from "../core";
|
|
6
|
+
import { AccountAuthenticator } from "../transactions/authenticator/account";
|
|
7
|
+
import {
|
|
8
|
+
AnyRawTransaction,
|
|
9
|
+
FeePayerTransaction,
|
|
10
|
+
GenerateMultiAgentRawTransactionInput,
|
|
11
|
+
GenerateTransactionInput,
|
|
12
|
+
GenerateFeePayerRawTransactionInput,
|
|
13
|
+
GenerateSingleSignerRawTransactionInput,
|
|
14
|
+
MultiAgentTransaction,
|
|
15
|
+
SingleSignerTransaction,
|
|
16
|
+
SimulateTransactionData,
|
|
17
|
+
} from "../transactions/types";
|
|
18
|
+
import { UserTransactionResponse, PendingTransactionResponse } from "../types";
|
|
19
|
+
import {
|
|
20
|
+
generateTransaction,
|
|
21
|
+
signTransaction,
|
|
22
|
+
simulateTransaction,
|
|
23
|
+
submitTransaction,
|
|
24
|
+
} from "../internal/transactionSubmission";
|
|
25
|
+
|
|
26
|
+
export class TransactionSubmission {
|
|
27
|
+
readonly config: AptosConfig;
|
|
28
|
+
|
|
29
|
+
constructor(config: AptosConfig) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* We are defining function signatures, each with its specific input and output.
|
|
35
|
+
* These are the possible function signature for `generateTransaction` function.
|
|
36
|
+
* When we call `generateTransaction` function with the relevant type properties,
|
|
37
|
+
* Typescript can infer the return type based on the appropriate function overload.
|
|
38
|
+
*/
|
|
39
|
+
async generateTransaction(args: GenerateSingleSignerRawTransactionInput): Promise<SingleSignerTransaction>;
|
|
40
|
+
async generateTransaction(args: GenerateFeePayerRawTransactionInput): Promise<FeePayerTransaction>;
|
|
41
|
+
async generateTransaction(args: GenerateMultiAgentRawTransactionInput): Promise<MultiAgentTransaction>;
|
|
42
|
+
async generateTransaction(args: GenerateTransactionInput): Promise<AnyRawTransaction>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Generates any transaction by passing in the required arguments
|
|
46
|
+
*
|
|
47
|
+
* @param args.sender The transaction sender's account address as a HexInput
|
|
48
|
+
* @param args.data EntryFunctionData | ScriptData | MultiSigData
|
|
49
|
+
* @param args.feePayerAddress optional. For a fee payer (aka sponsored) transaction
|
|
50
|
+
* @param args.secondarySignerAddresses optional. For a multi-agent or fee payer (aka sponsored) transactions
|
|
51
|
+
* @param args.options optional. GenerateTransactionOptions type
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* For a single signer entry function
|
|
55
|
+
* move function name, move function type arguments, move function arguments
|
|
56
|
+
* `
|
|
57
|
+
* data: {
|
|
58
|
+
* function:"0x1::aptos_account::transfer",
|
|
59
|
+
* type_arguments:[]
|
|
60
|
+
* arguments:[receiverAddress,10]
|
|
61
|
+
* }
|
|
62
|
+
* `
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* For a single signer script function
|
|
66
|
+
* module bytecode, move function type arguments, move function arguments
|
|
67
|
+
* ```
|
|
68
|
+
* data: {
|
|
69
|
+
* bytecode:"0x001234567",
|
|
70
|
+
* type_arguments:[],
|
|
71
|
+
* arguments:[receiverAddress,10]
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @return A raw transaction type (note that it holds the raw transaction as a bcs serialized data)
|
|
76
|
+
* ```
|
|
77
|
+
* {
|
|
78
|
+
* rawTransaction: Uint8Array,
|
|
79
|
+
* secondarySignerAddresses? : Array<AccountAddress>,
|
|
80
|
+
* feePayerAddress?: AccountAddress
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async generateTransaction(args: GenerateTransactionInput): Promise<AnyRawTransaction> {
|
|
85
|
+
return generateTransaction({ aptosConfig: this.config, ...args });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sign a transaction that can later be submitted to chain
|
|
90
|
+
*
|
|
91
|
+
* @param args.signer The signer account to sign the transaction
|
|
92
|
+
* @param args.transaction A raw transaction type (note that it holds the raw transaction as a bcs serialized data)
|
|
93
|
+
* ```
|
|
94
|
+
* {
|
|
95
|
+
* rawTransaction: Uint8Array,
|
|
96
|
+
* secondarySignerAddresses? : Array<AccountAddress>,
|
|
97
|
+
* feePayerAddress?: AccountAddress
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @return The signer AccountAuthenticator
|
|
102
|
+
*/
|
|
103
|
+
/* eslint-disable class-methods-use-this */
|
|
104
|
+
signTransaction(args: { signer: Account; transaction: AnyRawTransaction }): AccountAuthenticator {
|
|
105
|
+
return signTransaction({ ...args });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Simulates a transaction before singing it.
|
|
110
|
+
*
|
|
111
|
+
* @param args.signerPublicKey The signer public key
|
|
112
|
+
* @param args.transaction The raw transaction to simulate
|
|
113
|
+
* @param args.secondarySignersPublicKeys optional. For when the transaction is a multi signers transaction
|
|
114
|
+
* @param args.feePayerPublicKey optional. For when the transaction is a fee payer (aka sponsored) transaction
|
|
115
|
+
* @param args.options optional. A config to simulate the transaction with
|
|
116
|
+
*/
|
|
117
|
+
async simulateTransaction(args: SimulateTransactionData): Promise<Array<UserTransactionResponse>> {
|
|
118
|
+
return simulateTransaction({ aptosConfig: this.config, ...args });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Submit transaction to chain
|
|
123
|
+
*
|
|
124
|
+
* @param args.transaction A aptos transaction type
|
|
125
|
+
* @param args.senderAuthenticator The account authenticator of the transaction sender
|
|
126
|
+
* @param args.secondarySignerAuthenticators optional. For when the transaction is a multi signers transaction
|
|
127
|
+
*
|
|
128
|
+
* @return PendingTransactionResponse
|
|
129
|
+
*/
|
|
130
|
+
async submitTransaction(args: {
|
|
131
|
+
transaction: AnyRawTransaction;
|
|
132
|
+
senderAuthenticator: AccountAuthenticator;
|
|
133
|
+
secondarySignerAuthenticators?: {
|
|
134
|
+
feePayerAuthenticator?: AccountAuthenticator;
|
|
135
|
+
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
|
|
136
|
+
};
|
|
137
|
+
}): Promise<PendingTransactionResponse> {
|
|
138
|
+
return submitTransaction({ aptosConfig: this.config, ...args });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sign and submit a single signer transaction to chain
|
|
143
|
+
*
|
|
144
|
+
* @param args.signer The signer account to sign the transaction
|
|
145
|
+
* @param args.transaction A raw transaction type (note that it holds the raw transaction as a bcs serialized data)
|
|
146
|
+
* ```
|
|
147
|
+
* {
|
|
148
|
+
* rawTransaction: Uint8Array,
|
|
149
|
+
* secondarySignerAddresses? : Array<AccountAddress>,
|
|
150
|
+
* feePayerAddress?: AccountAddress
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @return PendingTransactionResponse
|
|
155
|
+
*/
|
|
156
|
+
async signAndSubmitTransaction(args: {
|
|
157
|
+
signer: Account;
|
|
158
|
+
transaction: AnyRawTransaction;
|
|
159
|
+
}): Promise<PendingTransactionResponse> {
|
|
160
|
+
const { signer, transaction } = args;
|
|
161
|
+
const authenticator = signTransaction({ signer, transaction });
|
|
162
|
+
return submitTransaction({
|
|
163
|
+
aptosConfig: this.config,
|
|
164
|
+
transaction,
|
|
165
|
+
senderAuthenticator: authenticator,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Uint8, Uint16, Uint32, Uint64, Uint128, Uint256 } from "../types";
|
|
5
|
+
|
|
6
|
+
// Upper bound values for uint8, uint16, uint64 and uint128
|
|
7
|
+
export const MAX_U8_NUMBER: Uint8 = 2 ** 8 - 1;
|
|
8
|
+
export const MAX_U16_NUMBER: Uint16 = 2 ** 16 - 1;
|
|
9
|
+
export const MAX_U32_NUMBER: Uint32 = 2 ** 32 - 1;
|
|
10
|
+
export const MAX_U64_BIG_INT: Uint64 = BigInt(2) ** BigInt(64) - BigInt(1);
|
|
11
|
+
export const MAX_U128_BIG_INT: Uint128 = BigInt(2) ** BigInt(128) - BigInt(1);
|
|
12
|
+
export const MAX_U256_BIG_INT: Uint256 = BigInt(2) ** BigInt(256) - BigInt(1);
|