@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
package/src/api/aptos.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Account } from "./account";
|
|
5
|
+
import { AptosConfig } from "./aptosConfig";
|
|
6
|
+
import { Coin } from "./coin";
|
|
7
|
+
import { DigitalAsset } from "./digitalAsset";
|
|
8
|
+
import { Event } from "./event";
|
|
9
|
+
import { Faucet } from "./faucet";
|
|
10
|
+
import { FungibleAsset } from "./fungibleAsset";
|
|
11
|
+
import { General } from "./general";
|
|
12
|
+
import { Staking } from "./staking";
|
|
13
|
+
import { Transaction } from "./transaction";
|
|
14
|
+
import { TransactionSubmission } from "./transactionSubmission";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This class is the main entry point into Aptos's
|
|
18
|
+
* APIs and separates functionality into different namespaces.
|
|
19
|
+
*
|
|
20
|
+
* To use the SDK, create a new Aptos instance to get access
|
|
21
|
+
* to all the sdk functionality.
|
|
22
|
+
*/
|
|
23
|
+
export class Aptos {
|
|
24
|
+
readonly config: AptosConfig;
|
|
25
|
+
|
|
26
|
+
readonly account: Account;
|
|
27
|
+
|
|
28
|
+
readonly coin: Coin;
|
|
29
|
+
|
|
30
|
+
readonly digitalAsset: DigitalAsset;
|
|
31
|
+
|
|
32
|
+
readonly event: Event;
|
|
33
|
+
|
|
34
|
+
readonly faucet: Faucet;
|
|
35
|
+
|
|
36
|
+
readonly fungibleAsset: FungibleAsset;
|
|
37
|
+
|
|
38
|
+
readonly general: General;
|
|
39
|
+
|
|
40
|
+
readonly staking: Staking;
|
|
41
|
+
|
|
42
|
+
readonly transaction: Transaction;
|
|
43
|
+
|
|
44
|
+
readonly transactionSubmission: TransactionSubmission;
|
|
45
|
+
|
|
46
|
+
constructor(settings?: AptosConfig) {
|
|
47
|
+
this.config = new AptosConfig(settings);
|
|
48
|
+
this.account = new Account(this.config);
|
|
49
|
+
this.coin = new Coin(this.config);
|
|
50
|
+
this.digitalAsset = new DigitalAsset(this.config);
|
|
51
|
+
this.event = new Event(this.config);
|
|
52
|
+
this.faucet = new Faucet(this.config);
|
|
53
|
+
this.fungibleAsset = new FungibleAsset(this.config);
|
|
54
|
+
this.general = new General(this.config);
|
|
55
|
+
this.staking = new Staking(this.config);
|
|
56
|
+
this.transaction = new Transaction(this.config);
|
|
57
|
+
this.transactionSubmission = new TransactionSubmission(this.config);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Aptos
|
|
62
|
+
extends Account,
|
|
63
|
+
Coin,
|
|
64
|
+
DigitalAsset,
|
|
65
|
+
Event,
|
|
66
|
+
Faucet,
|
|
67
|
+
FungibleAsset,
|
|
68
|
+
General,
|
|
69
|
+
Staking,
|
|
70
|
+
Transaction,
|
|
71
|
+
TransactionSubmission {}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
In TypeScript, we can’t inherit or extend from more than one class,
|
|
75
|
+
Mixins helps us to get around that by creating a partial classes
|
|
76
|
+
that we can combine to form a single class that contains all the methods and properties from the partial classes.
|
|
77
|
+
{@link https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern}
|
|
78
|
+
|
|
79
|
+
Here, we combine any subclass and the Aptos class.
|
|
80
|
+
*/
|
|
81
|
+
function applyMixin(targetClass: any, baseClass: any, baseClassProp: string) {
|
|
82
|
+
// Mixin instance methods
|
|
83
|
+
Object.getOwnPropertyNames(baseClass.prototype).forEach((propertyName) => {
|
|
84
|
+
const propertyDescriptor = Object.getOwnPropertyDescriptor(baseClass.prototype, propertyName);
|
|
85
|
+
if (!propertyDescriptor) return;
|
|
86
|
+
// eslint-disable-next-line func-names
|
|
87
|
+
propertyDescriptor.value = function (...args: any) {
|
|
88
|
+
return (this as any)[baseClassProp][propertyName](...args);
|
|
89
|
+
};
|
|
90
|
+
Object.defineProperty(targetClass.prototype, propertyName, propertyDescriptor);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
applyMixin(Aptos, Account, "account");
|
|
95
|
+
applyMixin(Aptos, Coin, "coin");
|
|
96
|
+
applyMixin(Aptos, DigitalAsset, "digitalAsset");
|
|
97
|
+
applyMixin(Aptos, Event, "event");
|
|
98
|
+
applyMixin(Aptos, Faucet, "faucet");
|
|
99
|
+
applyMixin(Aptos, FungibleAsset, "fungibleAsset");
|
|
100
|
+
applyMixin(Aptos, General, "general");
|
|
101
|
+
applyMixin(Aptos, Staking, "staking");
|
|
102
|
+
applyMixin(Aptos, Transaction, "transaction");
|
|
103
|
+
applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosSettings, ClientConfig } from "../types";
|
|
5
|
+
import { NetworkToNodeAPI, NetworkToFaucetAPI, NetworkToIndexerAPI, Network } from "../utils/apiEndpoints";
|
|
6
|
+
import { AptosApiType, DEFAULT_NETWORK } from "../utils/const";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This class holds the config information for the SDK client instance.
|
|
10
|
+
*/
|
|
11
|
+
export class AptosConfig {
|
|
12
|
+
/** The Network that this SDK is associated with. */
|
|
13
|
+
readonly network: Network;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The optional hardcoded fullnode URL to send requests to instead of using the network
|
|
17
|
+
*/
|
|
18
|
+
readonly fullnode?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The optional hardcoded faucet URL to send requests to instead of using the network
|
|
22
|
+
*/
|
|
23
|
+
readonly faucet?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The optional hardcoded indexer URL to send requests to instead of using the network
|
|
27
|
+
*/
|
|
28
|
+
readonly indexer?: string;
|
|
29
|
+
|
|
30
|
+
readonly clientConfig?: ClientConfig;
|
|
31
|
+
|
|
32
|
+
constructor(settings?: AptosSettings) {
|
|
33
|
+
this.network = settings?.network ?? DEFAULT_NETWORK;
|
|
34
|
+
this.fullnode = settings?.fullnode;
|
|
35
|
+
this.faucet = settings?.faucet;
|
|
36
|
+
this.indexer = settings?.indexer;
|
|
37
|
+
this.clientConfig = settings?.clientConfig ?? {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the URL endpoint to send the request to.
|
|
42
|
+
* If a custom URL was provided in the config, that URL is returned.
|
|
43
|
+
* If a custom URL was provided but not URL endpoints, an error is thrown.
|
|
44
|
+
* Otherwise, the URL endpoint is derived from the network.
|
|
45
|
+
*
|
|
46
|
+
* @param apiType - The type of Aptos API to get the URL for.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
getRequestUrl(apiType: AptosApiType): string {
|
|
51
|
+
switch (apiType) {
|
|
52
|
+
case AptosApiType.FULLNODE:
|
|
53
|
+
if (this.fullnode !== undefined) return this.fullnode;
|
|
54
|
+
if (this.network === Network.CUSTOM) throw new Error("Please provide a custom full node url");
|
|
55
|
+
return NetworkToNodeAPI[this.network];
|
|
56
|
+
case AptosApiType.FAUCET:
|
|
57
|
+
if (this.faucet !== undefined) return this.faucet;
|
|
58
|
+
if (this.network === Network.CUSTOM) throw new Error("Please provide a custom faucet url");
|
|
59
|
+
return NetworkToFaucetAPI[this.network];
|
|
60
|
+
case AptosApiType.INDEXER:
|
|
61
|
+
if (this.indexer !== undefined) return this.indexer;
|
|
62
|
+
if (this.network === Network.CUSTOM) throw new Error("Please provide a custom indexer url");
|
|
63
|
+
return NetworkToIndexerAPI[this.network];
|
|
64
|
+
default:
|
|
65
|
+
throw Error(`apiType ${apiType} is not supported`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks if the URL is a known indexer endpoint
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
* */
|
|
74
|
+
isIndexerRequest(url: string): boolean {
|
|
75
|
+
return NetworkToIndexerAPI[this.network] === url;
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/api/coin.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import { Account } from "../core";
|
|
6
|
+
import { transferCoinTransaction } from "../internal/coin";
|
|
7
|
+
import { SingleSignerTransaction, GenerateTransactionOptions } from "../transactions/types";
|
|
8
|
+
import { AnyNumber, HexInput, MoveResourceType } from "../types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A class to handle all `Coin` operations
|
|
12
|
+
*/
|
|
13
|
+
export class Coin {
|
|
14
|
+
readonly config: AptosConfig;
|
|
15
|
+
|
|
16
|
+
constructor(config: AptosConfig) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generate a transfer coin transaction that can be simulated and/or signed and submitted
|
|
22
|
+
*
|
|
23
|
+
* @param args.sender The sender account
|
|
24
|
+
* @param args.recipient The recipient address
|
|
25
|
+
* @param args.amount The amount to transfer
|
|
26
|
+
* @param args.coinType optional. The coin struct type to transfer. Defaults to 0x1::aptos_coin::AptosCoin
|
|
27
|
+
*
|
|
28
|
+
* @returns SingleSignerTransaction
|
|
29
|
+
*/
|
|
30
|
+
async transferCoinTransaction(args: {
|
|
31
|
+
sender: Account;
|
|
32
|
+
recipient: HexInput;
|
|
33
|
+
amount: AnyNumber;
|
|
34
|
+
coinType?: MoveResourceType;
|
|
35
|
+
options?: GenerateTransactionOptions;
|
|
36
|
+
}): Promise<SingleSignerTransaction> {
|
|
37
|
+
return transferCoinTransaction({ aptosConfig: this.config, ...args });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GetCollectionDataResponse,
|
|
6
|
+
GetCurrentTokenOwnershipResponse,
|
|
7
|
+
GetOwnedTokensResponse,
|
|
8
|
+
GetTokenActivityResponse,
|
|
9
|
+
GetTokenDataResponse,
|
|
10
|
+
HexInput,
|
|
11
|
+
OrderBy,
|
|
12
|
+
PaginationArgs,
|
|
13
|
+
TokenStandard,
|
|
14
|
+
} from "../types";
|
|
15
|
+
import { AptosConfig } from "./aptosConfig";
|
|
16
|
+
import { Account } from "../core";
|
|
17
|
+
import { GenerateTransactionOptions, SingleSignerTransaction } from "../transactions/types";
|
|
18
|
+
import {
|
|
19
|
+
CreateCollectionOptions,
|
|
20
|
+
createCollectionTransaction,
|
|
21
|
+
getCollectionData,
|
|
22
|
+
getCollectionId,
|
|
23
|
+
getCurrentTokenOwnership,
|
|
24
|
+
getOwnedTokens,
|
|
25
|
+
getTokenActivity,
|
|
26
|
+
getTokenData,
|
|
27
|
+
mintTokenTransaction,
|
|
28
|
+
} from "../internal/digitalAsset";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A class to query all `DigitalAsset` related queries on Aptos.
|
|
32
|
+
*/
|
|
33
|
+
export class DigitalAsset {
|
|
34
|
+
readonly config: AptosConfig;
|
|
35
|
+
|
|
36
|
+
constructor(config: AptosConfig) {
|
|
37
|
+
this.config = config;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new collection within the specified account
|
|
42
|
+
*
|
|
43
|
+
* @param args.creator the account of the collection's creator
|
|
44
|
+
* @param args.description the description of the collection
|
|
45
|
+
* @param args.name the name of the collection
|
|
46
|
+
* @param args.uri the URI to additional info about the collection
|
|
47
|
+
*
|
|
48
|
+
* The parameters below are optional.
|
|
49
|
+
* @param args.maxSupply controls the max supply of the tokens - defaults MAX_U64_BIG_INT
|
|
50
|
+
* @param args.mutableDescription controls mutability of the collection's description - defaults true
|
|
51
|
+
* @param args.mutableRoyalty controls mutability of the collection's description - defaults true
|
|
52
|
+
* @param args.mutableUri controls mutability of the collection's URI - defaults true
|
|
53
|
+
* @param args.mutableTokenDescription controls mutability of the token's description - defaults true
|
|
54
|
+
* @param args.mutableTokenName controls mutability of the token's name - defaults true
|
|
55
|
+
* @param args.mutableTokenProperties controls mutability of token's properties - defaults true
|
|
56
|
+
* @param args.mutableTokenUri controls mutability of the token's URI - defaults true
|
|
57
|
+
* @param args.tokensBurnableByCreator controls whether tokens can be burnable by the creator - defaults true
|
|
58
|
+
* @param args.tokensFreezableByCreator controls whether tokens can be frozen by the creator - defaults true
|
|
59
|
+
* @param args.royaltyNumerator the numerator of the royalty to be paid to the creator when a token is transferred - defaults 0
|
|
60
|
+
* @param args.royaltyDenominator the denominator of the royalty to be paid to the creator when a token is transferred -
|
|
61
|
+
* defaults 1
|
|
62
|
+
*
|
|
63
|
+
* @returns A SingleSignerTransaction that when submitted will create the collection.
|
|
64
|
+
*/
|
|
65
|
+
async createCollectionTransaction(
|
|
66
|
+
args: {
|
|
67
|
+
creator: Account;
|
|
68
|
+
description: string;
|
|
69
|
+
name: string;
|
|
70
|
+
uri: string;
|
|
71
|
+
options?: GenerateTransactionOptions;
|
|
72
|
+
} & CreateCollectionOptions,
|
|
73
|
+
): Promise<SingleSignerTransaction> {
|
|
74
|
+
return createCollectionTransaction({ aptosConfig: this.config, ...args });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Queries data of a specific collection by the collection creator address and the collection name.
|
|
79
|
+
*
|
|
80
|
+
* If, for some reason, a creator account has 2 collections with the same name in v1 and v2,
|
|
81
|
+
* can pass an optional `tokenStandard` parameter to query a specific standard
|
|
82
|
+
*
|
|
83
|
+
* @param args.creatorAddress the address of the collection's creator
|
|
84
|
+
* @param args.collectionName the name of the collection
|
|
85
|
+
* @param args.options.tokenStandard the token standard to query
|
|
86
|
+
* @returns GetCollectionDataResponse response type
|
|
87
|
+
*/
|
|
88
|
+
async getCollectionData(args: {
|
|
89
|
+
creatorAddress: HexInput;
|
|
90
|
+
collectionName: string;
|
|
91
|
+
options?: {
|
|
92
|
+
tokenStandard?: TokenStandard;
|
|
93
|
+
};
|
|
94
|
+
}): Promise<GetCollectionDataResponse> {
|
|
95
|
+
return getCollectionData({ aptosConfig: this.config, ...args });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Queries a collection's ID.
|
|
100
|
+
*
|
|
101
|
+
* This is the same as the collection's object address in V2, but V1 does
|
|
102
|
+
* not use objects, and does not have an address
|
|
103
|
+
*
|
|
104
|
+
* @param args.creatorAddress the address of the collection's creator
|
|
105
|
+
* @param args.collectionName the name of the collection
|
|
106
|
+
* @param args.options.tokenStandard the token standard to query
|
|
107
|
+
* @returns the collection id
|
|
108
|
+
*/
|
|
109
|
+
async getCollectionId(args: {
|
|
110
|
+
creatorAddress: HexInput;
|
|
111
|
+
collectionName: string;
|
|
112
|
+
options?: {
|
|
113
|
+
tokenStandard?: TokenStandard;
|
|
114
|
+
};
|
|
115
|
+
}): Promise<string> {
|
|
116
|
+
return getCollectionId({ aptosConfig: this.config, ...args });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Create a transaction to mint a token into the creators account within an existing collection.
|
|
121
|
+
*
|
|
122
|
+
* @param args.creator the creator of the collection
|
|
123
|
+
* @param args.collection the name of the collection the token belongs to
|
|
124
|
+
* @param args.description the description of the token
|
|
125
|
+
* @param args.name the name of the token
|
|
126
|
+
* @param args.uri the URI to additional info about the token
|
|
127
|
+
*
|
|
128
|
+
* @returns A SingleSignerTransaction that can be simulated or submitted to chain
|
|
129
|
+
*/
|
|
130
|
+
async mintTokenTransaction(args: {
|
|
131
|
+
creator: Account;
|
|
132
|
+
collection: string;
|
|
133
|
+
description: string;
|
|
134
|
+
name: string;
|
|
135
|
+
uri: string;
|
|
136
|
+
options?: GenerateTransactionOptions;
|
|
137
|
+
}): Promise<SingleSignerTransaction> {
|
|
138
|
+
return mintTokenTransaction({ aptosConfig: this.config, ...args });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Gets token data given the address of a token.
|
|
143
|
+
*
|
|
144
|
+
* @param args.tokenAddress The address of the token
|
|
145
|
+
* @returns GetTokenDataResponse containing relevant data to the token.
|
|
146
|
+
*/
|
|
147
|
+
async getTokenData(args: { tokenAddress: HexInput }): Promise<GetTokenDataResponse> {
|
|
148
|
+
return getTokenData({ aptosConfig: this.config, ...args });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Gets token ownership data given the address of a token.
|
|
153
|
+
*
|
|
154
|
+
* @param args.tokenAddress The address of the token
|
|
155
|
+
* @returns GetCurrentTokenOwnershipResponse containing relevant ownership data of the token.
|
|
156
|
+
*/
|
|
157
|
+
async getCurrentTokenOwnership(args: { tokenAddress: HexInput }): Promise<GetCurrentTokenOwnershipResponse> {
|
|
158
|
+
return getCurrentTokenOwnership({ aptosConfig: this.config, ...args });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Gets the tokens that the given address owns.
|
|
163
|
+
*
|
|
164
|
+
* @param args.ownerAddress The address of the owner
|
|
165
|
+
* @returns GetOwnedTokensResponse containing ownership data of the tokens belonging to the ownerAddresss.
|
|
166
|
+
*/
|
|
167
|
+
async getOwnedTokens(args: {
|
|
168
|
+
ownerAddress: HexInput;
|
|
169
|
+
options?: {
|
|
170
|
+
pagination?: PaginationArgs;
|
|
171
|
+
orderBy?: OrderBy<GetOwnedTokensResponse[0]>;
|
|
172
|
+
};
|
|
173
|
+
}): Promise<GetOwnedTokensResponse> {
|
|
174
|
+
return getOwnedTokens({ aptosConfig: this.config, ...args });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Gets the activity data given the address of a token.
|
|
179
|
+
*
|
|
180
|
+
* @param args.tokenAddress The address of the token
|
|
181
|
+
* @returns GetTokenActivityResponse containing relevant activity data to the token.
|
|
182
|
+
*/
|
|
183
|
+
async getTokenActivity(args: {
|
|
184
|
+
tokenAddress: HexInput;
|
|
185
|
+
options?: {
|
|
186
|
+
pagination?: PaginationArgs;
|
|
187
|
+
orderBy?: OrderBy<GetTokenActivityResponse[0]>;
|
|
188
|
+
};
|
|
189
|
+
}): Promise<GetTokenActivityResponse> {
|
|
190
|
+
return getTokenActivity({ aptosConfig: this.config, ...args });
|
|
191
|
+
}
|
|
192
|
+
}
|
package/src/api/event.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import { getAccountEventsByCreationNumber, getAccountEventsByEventType, getEvents } from "../internal/event";
|
|
6
|
+
import { AnyNumber, GetEventsResponse, HexInput, MoveResourceType, OrderBy, PaginationArgs } from "../types";
|
|
7
|
+
import { EventsBoolExp } from "../types/generated/types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A class to query all `Event` Aptos related queries
|
|
11
|
+
*/
|
|
12
|
+
export class Event {
|
|
13
|
+
readonly config: AptosConfig;
|
|
14
|
+
|
|
15
|
+
constructor(config: AptosConfig) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get events by creation number and an account address
|
|
21
|
+
*
|
|
22
|
+
* @param args.accountAddress - The account address
|
|
23
|
+
* @param args.creationNumber - The event creation number
|
|
24
|
+
*
|
|
25
|
+
* @returns Promise<GetEventsResponse>
|
|
26
|
+
*/
|
|
27
|
+
async getAccountEventsByCreationNumber(args: {
|
|
28
|
+
accountAddress: HexInput;
|
|
29
|
+
creationNumber: AnyNumber;
|
|
30
|
+
}): Promise<GetEventsResponse> {
|
|
31
|
+
return getAccountEventsByCreationNumber({ aptosConfig: this.config, ...args });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get events by event type and an account address
|
|
36
|
+
*
|
|
37
|
+
* @param args.accountAddress - The account address
|
|
38
|
+
* @param args.eventType - The event type
|
|
39
|
+
*
|
|
40
|
+
* @returns Promise<GetEventsResponse>
|
|
41
|
+
*/
|
|
42
|
+
async getAccountEventsByEventType(args: {
|
|
43
|
+
accountAddress: HexInput;
|
|
44
|
+
eventType: MoveResourceType;
|
|
45
|
+
options?: {
|
|
46
|
+
pagination?: PaginationArgs;
|
|
47
|
+
orderBy?: OrderBy<GetEventsResponse[0]>;
|
|
48
|
+
};
|
|
49
|
+
}): Promise<GetEventsResponse> {
|
|
50
|
+
return getAccountEventsByEventType({ aptosConfig: this.config, ...args });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get all events
|
|
55
|
+
*
|
|
56
|
+
* An optional `where` can be passed in to filter out the response.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```
|
|
60
|
+
* { where:
|
|
61
|
+
* {
|
|
62
|
+
* transaction_version: { _eq: 123456 },
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @returns GetEventsQuery response type
|
|
68
|
+
*/
|
|
69
|
+
async getEvents(args?: {
|
|
70
|
+
options?: {
|
|
71
|
+
where?: EventsBoolExp;
|
|
72
|
+
pagination?: PaginationArgs;
|
|
73
|
+
orderBy?: OrderBy<GetEventsResponse[0]>;
|
|
74
|
+
};
|
|
75
|
+
}): Promise<GetEventsResponse> {
|
|
76
|
+
return getEvents({ aptosConfig: this.config, ...args });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AptosConfig } from "./aptosConfig";
|
|
5
|
+
import { fundAccount } from "../internal/faucet";
|
|
6
|
+
import { HexInput } from "../types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A class to query all `Faucet` related queries on Aptos.
|
|
10
|
+
*/
|
|
11
|
+
export class Faucet {
|
|
12
|
+
readonly config: AptosConfig;
|
|
13
|
+
|
|
14
|
+
constructor(config: AptosConfig) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This creates an account if it does not exist and mints the specified amount of
|
|
20
|
+
* coins into that account
|
|
21
|
+
*
|
|
22
|
+
* @param args.accountAddress Address of the account to fund
|
|
23
|
+
* @param args.amount Amount of tokens to fund the account with
|
|
24
|
+
* @param args.timeoutSecs Timeout in seconds. Defaults to 20 seconds.
|
|
25
|
+
* @returns Transaction hash of the transaction that funded the account
|
|
26
|
+
*/
|
|
27
|
+
async fundAccount(args: { accountAddress: HexInput; amount: number; timeoutSecs?: number }): Promise<string> {
|
|
28
|
+
return fundAccount({ aptosConfig: this.config, ...args });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GetCurrentFungibleAssetBalancesResponse,
|
|
6
|
+
GetFungibleAssetActivitiesResponse,
|
|
7
|
+
GetFungibleAssetMetadataResponse,
|
|
8
|
+
PaginationArgs,
|
|
9
|
+
} from "../types";
|
|
10
|
+
import { AptosConfig } from "./aptosConfig";
|
|
11
|
+
import {
|
|
12
|
+
getCurrentFungibleAssetBalances,
|
|
13
|
+
getFungibleAssetActivities,
|
|
14
|
+
getFungibleAssetMetadata,
|
|
15
|
+
} from "../internal/fungibleAsset";
|
|
16
|
+
import {
|
|
17
|
+
CurrentFungibleAssetBalancesBoolExp,
|
|
18
|
+
FungibleAssetActivitiesBoolExp,
|
|
19
|
+
FungibleAssetMetadataBoolExp,
|
|
20
|
+
} from "../types/generated/types";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A class to query all `FungibleAsset` related queries on Aptos.
|
|
24
|
+
*/
|
|
25
|
+
export class FungibleAsset {
|
|
26
|
+
readonly config: AptosConfig;
|
|
27
|
+
|
|
28
|
+
constructor(config: AptosConfig) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Queries the current fungible asset metadata.
|
|
34
|
+
*
|
|
35
|
+
* This query returns the fungible asset metadata for all fungible assets.
|
|
36
|
+
* It can be filtered by creator address and asset type.
|
|
37
|
+
*
|
|
38
|
+
* @returns getFungibleAssetMetadata A list of fungible asset metadata
|
|
39
|
+
*/
|
|
40
|
+
async getFungibleAssetMetadata(args?: {
|
|
41
|
+
options?: {
|
|
42
|
+
pagination?: PaginationArgs;
|
|
43
|
+
where?: FungibleAssetMetadataBoolExp;
|
|
44
|
+
};
|
|
45
|
+
}): Promise<GetFungibleAssetMetadataResponse> {
|
|
46
|
+
return getFungibleAssetMetadata({ aptosConfig: this.config, ...args });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Queries the fungible asset activities
|
|
51
|
+
*
|
|
52
|
+
* This query returns the fungible asset activities.
|
|
53
|
+
* It can be filtered by owner address, asset type, and type.
|
|
54
|
+
*
|
|
55
|
+
* @returns GetFungibleAssetActivitiesResponse A list of fungible asset metadata
|
|
56
|
+
*/
|
|
57
|
+
async getFungibleAssetActivities(args?: {
|
|
58
|
+
options?: {
|
|
59
|
+
pagination?: PaginationArgs;
|
|
60
|
+
where?: FungibleAssetActivitiesBoolExp;
|
|
61
|
+
};
|
|
62
|
+
}): Promise<GetFungibleAssetActivitiesResponse> {
|
|
63
|
+
return getFungibleAssetActivities({ aptosConfig: this.config, ...args });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Queries the fungible asset balance
|
|
68
|
+
*
|
|
69
|
+
* This query returns the fungible asset balance.
|
|
70
|
+
* It can be filtered by owner address, and asset type
|
|
71
|
+
*
|
|
72
|
+
* @returns GetCurrentFungibleAssetBalancesResponse A list of fungible asset metadata
|
|
73
|
+
*/
|
|
74
|
+
async getCurrentFungibleAssetBalances(args?: {
|
|
75
|
+
options?: {
|
|
76
|
+
pagination?: PaginationArgs;
|
|
77
|
+
where?: CurrentFungibleAssetBalancesBoolExp;
|
|
78
|
+
};
|
|
79
|
+
}): Promise<GetCurrentFungibleAssetBalancesResponse> {
|
|
80
|
+
return getCurrentFungibleAssetBalances({ aptosConfig: this.config, ...args });
|
|
81
|
+
}
|
|
82
|
+
}
|