@coinbase/cdp-sdk 0.0.0 → 1.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.
Files changed (87) hide show
  1. package/README.md +165 -0
  2. package/dist/accounts/evm/toEvmServerAccount.d.ts +19 -0
  3. package/dist/accounts/evm/toEvmServerAccount.js +42 -0
  4. package/dist/accounts/evm/toEvmSmartAccount.d.ts +24 -0
  5. package/dist/accounts/evm/toEvmSmartAccount.js +24 -0
  6. package/dist/accounts/types.d.ts +45 -0
  7. package/dist/accounts/types.js +2 -0
  8. package/dist/actions/evm/sendUserOperation.d.ts +95 -0
  9. package/dist/actions/evm/sendUserOperation.js +87 -0
  10. package/dist/actions/evm/waitForUserOperation.d.ts +63 -0
  11. package/dist/actions/evm/waitForUserOperation.js +60 -0
  12. package/dist/analytics.d.ts +30 -0
  13. package/dist/analytics.js +89 -0
  14. package/dist/auth/errors.d.ts +45 -0
  15. package/dist/auth/errors.js +62 -0
  16. package/dist/auth/hooks/axios/index.d.ts +1 -0
  17. package/dist/auth/hooks/axios/index.js +17 -0
  18. package/dist/auth/hooks/axios/withAuth.d.ts +37 -0
  19. package/dist/auth/hooks/axios/withAuth.js +73 -0
  20. package/dist/auth/index.d.ts +4 -0
  21. package/dist/auth/index.js +43 -0
  22. package/dist/auth/utils/http.d.ts +60 -0
  23. package/dist/auth/utils/http.js +72 -0
  24. package/dist/auth/utils/index.d.ts +2 -0
  25. package/dist/auth/utils/index.js +18 -0
  26. package/dist/auth/utils/jwt.d.ts +88 -0
  27. package/dist/auth/utils/jwt.js +235 -0
  28. package/dist/client/cdp.d.ts +43 -0
  29. package/dist/client/cdp.js +40 -0
  30. package/dist/client/evm/evm.d.ts +387 -0
  31. package/dist/client/evm/evm.js +520 -0
  32. package/dist/client/evm/evm.types.d.ts +254 -0
  33. package/dist/client/evm/evm.types.js +2 -0
  34. package/dist/client/evm/index.d.ts +1 -0
  35. package/dist/client/evm/index.js +5 -0
  36. package/dist/client/solana/index.d.ts +1 -0
  37. package/dist/client/solana/index.js +5 -0
  38. package/dist/client/solana/solana.d.ts +168 -0
  39. package/dist/client/solana/solana.js +207 -0
  40. package/dist/client/solana/solana.types.d.ts +94 -0
  41. package/dist/client/solana/solana.types.js +2 -0
  42. package/dist/constants.d.ts +4 -0
  43. package/dist/constants.js +7 -0
  44. package/dist/errors.d.ts +11 -0
  45. package/dist/errors.js +21 -0
  46. package/dist/index.d.ts +3 -0
  47. package/dist/index.js +6 -0
  48. package/dist/openapi-client/cdpApiClient.d.ts +50 -0
  49. package/dist/openapi-client/cdpApiClient.js +146 -0
  50. package/dist/openapi-client/errors.d.ts +53 -0
  51. package/dist/openapi-client/errors.js +70 -0
  52. package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +345 -0
  53. package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +54 -0
  54. package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +62 -0
  55. package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +85 -0
  56. package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +17 -0
  57. package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +113 -0
  58. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +48 -0
  59. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +66 -0
  60. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +15 -0
  61. package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +99 -0
  62. package/dist/openapi-client/generated/faucets/faucets.d.ts +48 -0
  63. package/dist/openapi-client/generated/faucets/faucets.js +51 -0
  64. package/dist/openapi-client/generated/faucets/faucets.msw.d.ts +7 -0
  65. package/dist/openapi-client/generated/faucets/faucets.msw.js +43 -0
  66. package/dist/openapi-client/generated/index.msw.d.ts +4 -0
  67. package/dist/openapi-client/generated/index.msw.js +20 -0
  68. package/dist/openapi-client/generated/solana-accounts/solana-accounts.d.ts +61 -0
  69. package/dist/openapi-client/generated/solana-accounts/solana-accounts.js +79 -0
  70. package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +15 -0
  71. package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.js +99 -0
  72. package/dist/openapi-client/index.d.ts +55 -0
  73. package/dist/openapi-client/index.js +65 -0
  74. package/dist/types/calls.d.ts +13 -0
  75. package/dist/types/calls.js +4 -0
  76. package/dist/types/contract.d.ts +30 -0
  77. package/dist/types/contract.js +4 -0
  78. package/dist/types/misc.d.ts +3 -0
  79. package/dist/types/misc.js +3 -0
  80. package/dist/types/multicall.d.ts +9 -0
  81. package/dist/types/multicall.js +2 -0
  82. package/dist/types/utils.d.ts +196 -0
  83. package/dist/types/utils.js +4 -0
  84. package/dist/utils/wait.d.ts +28 -0
  85. package/dist/utils/wait.js +34 -0
  86. package/package.json +72 -5
  87. package/index.js +0 -1
@@ -0,0 +1,254 @@
1
+ import type { EvmUserOperationNetwork, EvmUserOperationStatus, OpenApiEvmMethods } from "../../openapi-client";
2
+ import { EvmAccount as Account, EvmServerAccount as ServerAccount, EvmSmartAccount as SmartAccount } from "../../accounts/types";
3
+ import { Call, Calls } from "../../types/calls";
4
+ import { Address, Hex } from "../../types/misc";
5
+ import { WaitOptions } from "../../utils/wait";
6
+ import { SendUserOperationReturnType } from "../../actions/evm/sendUserOperation";
7
+ /**
8
+ * The EvmClient type, where all OpenApiEvmMethods methods are wrapped.
9
+ */
10
+ export type EvmClientInterface = Omit<typeof OpenApiEvmMethods, "createEvmAccount" | "createEvmSmartAccount" | "getEvmAccount" | "getEvmAccountByName" | "getEvmSmartAccount" | "getUserOperation" | "listEVMBalances" | "listEvmAccounts" | "listEvmSmartAccounts" | "prepareUserOperation" | "requestEvmFaucet" | "sendUserOperation" | "signEvmHash" | "signEvmMessage" | "signEvmTransaction"> & {
11
+ createAccount: (options: CreateServerAccountOptions) => Promise<ServerAccount>;
12
+ createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
13
+ getAccount: (options: GetServerAccountOptions) => Promise<ServerAccount>;
14
+ getSmartAccount: (options: GetSmartAccountOptions) => Promise<SmartAccount>;
15
+ getUserOperation: (options: GetUserOperationOptions) => Promise<UserOperation>;
16
+ listAccounts: (options: ListServerAccountsOptions) => Promise<ListServerAccountResult>;
17
+ listSmartAccounts: (options: ListSmartAccountsOptions) => Promise<ListSmartAccountResult>;
18
+ prepareUserOperation: (options: PrepareUserOperationOptions) => Promise<UserOperation>;
19
+ requestFaucet: (options: RequestFaucetOptions) => Promise<RequestFaucetResult>;
20
+ sendUserOperation: (options: SendUserOperationOptions) => Promise<SendUserOperationReturnType>;
21
+ signHash: (options: SignHashOptions) => Promise<SignatureResult>;
22
+ signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
23
+ signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
24
+ };
25
+ export type { ServerAccount, SmartAccount };
26
+ /**
27
+ * Options for getting a user operation.
28
+ */
29
+ export interface GetUserOperationOptions {
30
+ /** The smart account. */
31
+ smartAccount: SmartAccount;
32
+ /** The user operation hash. */
33
+ userOpHash: Hex;
34
+ }
35
+ /**
36
+ * Options for preparing a user operation.
37
+ */
38
+ export interface PrepareUserOperationOptions {
39
+ /** The smart account. */
40
+ smartAccount: SmartAccount;
41
+ /** The network. */
42
+ network: EvmUserOperationNetwork;
43
+ /** The calls. */
44
+ calls: Calls<EvmCall[]>;
45
+ /** The paymaster URL. */
46
+ paymasterUrl?: string;
47
+ }
48
+ /**
49
+ * A call to be executed in a user operation.
50
+ */
51
+ export interface EvmCall {
52
+ /**
53
+ * The address the call is directed to.
54
+ */
55
+ to: Address;
56
+ /** The amount of ETH to send with the call, in wei. */
57
+ value: bigint;
58
+ /**
59
+ * The call data to send. This is the hex-encoded data of the function call consisting of the method selector and the function arguments.
60
+ */
61
+ data: Hex;
62
+ }
63
+ /**
64
+ * A user operation.
65
+ */
66
+ export interface UserOperation {
67
+ /** The network the user operation is for. */
68
+ network: EvmUserOperationNetwork;
69
+ /**
70
+ * The hash of the user operation. This is not the transaction hash, as a transaction consists of multiple user operations. The user operation hash is the hash of this particular user operation which gets signed by the owner of the Smart Account.
71
+ */
72
+ userOpHash: Hex;
73
+ /** The list of calls in the user operation. */
74
+ calls: Calls<EvmCall[]>;
75
+ /** The status of the user operation. */
76
+ status: EvmUserOperationStatus;
77
+ /**
78
+ * The hash of the transaction that included this particular user operation. This gets set after the user operation is broadcasted and the transaction is included in a block.
79
+ */
80
+ transactionHash?: Hex;
81
+ }
82
+ /**
83
+ * Options for creating an EVM server account.
84
+ */
85
+ export interface CreateServerAccountOptions {
86
+ /** The name of the account. */
87
+ name?: string;
88
+ /** The idempotency key. */
89
+ idempotencyKey?: string;
90
+ }
91
+ /**
92
+ * Options for getting an EVM account.
93
+ */
94
+ export interface GetServerAccountOptions {
95
+ /** The address of the account. */
96
+ address?: Address;
97
+ /** The name of the account. */
98
+ name?: string;
99
+ }
100
+ /**
101
+ * Options for getting an EVM smart account.
102
+ */
103
+ export interface GetSmartAccountOptions {
104
+ /** The address of the account. */
105
+ address: Address;
106
+ /** The owner of the account. */
107
+ owner: Account;
108
+ }
109
+ /**
110
+ * Options for listing EVM accounts.
111
+ */
112
+ export interface ListServerAccountsOptions {
113
+ /** The page size to paginate through the accounts. */
114
+ pageSize?: number;
115
+ /** The page token to paginate through the accounts. */
116
+ pageToken?: string;
117
+ }
118
+ /**
119
+ * A smart account that only contains the owner address.
120
+ */
121
+ export interface ReadonlySmartAccount extends Omit<SmartAccount, "owners"> {
122
+ /** The owners of the smart account. */
123
+ owners: Address[];
124
+ }
125
+ /**
126
+ * The result of listing EVM smart accounts.
127
+ */
128
+ export interface ListSmartAccountResult {
129
+ /** The accounts. */
130
+ accounts: ReadonlySmartAccount[];
131
+ /**
132
+ * The next page token to paginate through the accounts.
133
+ * If undefined, there are no more accounts to paginate through.
134
+ */
135
+ nextPageToken?: string;
136
+ }
137
+ /**
138
+ * The result of listing EVM server accounts.
139
+ */
140
+ export interface ListServerAccountResult {
141
+ /** The accounts. */
142
+ accounts: ServerAccount[];
143
+ /**
144
+ * The next page token to paginate through the accounts.
145
+ * If undefined, there are no more accounts to paginate through.
146
+ */
147
+ nextPageToken?: string;
148
+ }
149
+ /**
150
+ * Options for listing EVM smart accounts.
151
+ */
152
+ export interface ListSmartAccountsOptions {
153
+ /** The name of the account. */
154
+ name?: string;
155
+ /** The page size to paginate through the accounts. */
156
+ pageSize?: number;
157
+ /** The page token to paginate through the accounts. */
158
+ pageToken?: string;
159
+ }
160
+ /**
161
+ * Options for creating an EVM smart account.
162
+ */
163
+ export interface CreateSmartAccountOptions {
164
+ /** The owner of the account. */
165
+ owner: Account;
166
+ /** The idempotency key. */
167
+ idempotencyKey?: string;
168
+ }
169
+ /**
170
+ * Options for requesting funds from an EVM faucet.
171
+ */
172
+ export interface RequestFaucetOptions {
173
+ /** The address of the account. */
174
+ address: string;
175
+ /** The network to request funds from. */
176
+ network: "base-sepolia" | "ethereum-sepolia";
177
+ /** The token to request funds for. */
178
+ token: "eth" | "usdc" | "eurc" | "cbbtc";
179
+ /** The idempotency key. */
180
+ idempotencyKey?: string;
181
+ }
182
+ /**
183
+ * The result of requesting funds from an EVM faucet.
184
+ */
185
+ export interface RequestFaucetResult {
186
+ /** The transaction hash. */
187
+ transactionHash: Hex;
188
+ }
189
+ /**
190
+ * Options for sending a user operation.
191
+ */
192
+ export interface SendUserOperationOptions {
193
+ /** The smart account. */
194
+ smartAccount: SmartAccount;
195
+ /** The network. */
196
+ network: EvmUserOperationNetwork;
197
+ /** The calls. */
198
+ calls: Call[];
199
+ /** The paymaster URL. */
200
+ paymasterUrl?: string;
201
+ /** The idempotency key. */
202
+ idempotencyKey?: string;
203
+ }
204
+ /**
205
+ * Options for signing an EVM hash.
206
+ */
207
+ export interface SignHashOptions {
208
+ /** The address of the account. */
209
+ address: Address;
210
+ /** The hash to sign. */
211
+ hash: Hex;
212
+ /** The idempotency key. */
213
+ idempotencyKey?: string;
214
+ }
215
+ /**
216
+ * Options for signing an EVM message.
217
+ */
218
+ export interface SignMessageOptions {
219
+ /** The address of the account. */
220
+ address: Address;
221
+ /** The message to sign. */
222
+ message: string;
223
+ /** The idempotency key. */
224
+ idempotencyKey?: string;
225
+ }
226
+ /**
227
+ * Options for signing an EVM transaction.
228
+ */
229
+ export interface SignTransactionOptions {
230
+ /** The address of the account. */
231
+ address: Address;
232
+ /** The RLP-encoded transaction to sign, as a 0x-prefixed hex string. */
233
+ transaction: Hex;
234
+ /** The idempotency key. */
235
+ idempotencyKey?: string;
236
+ }
237
+ /**
238
+ * A signature result.
239
+ */
240
+ export interface SignatureResult {
241
+ /** The signature. */
242
+ signature: Hex;
243
+ }
244
+ /**
245
+ * Options for waiting for a user operation.
246
+ */
247
+ export interface WaitForUserOperationOptions {
248
+ /** The smart account address. */
249
+ smartAccountAddress: Address;
250
+ /** The user operation hash. */
251
+ userOpHash: Hex;
252
+ /** The wait options. */
253
+ waitOptions?: WaitOptions;
254
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { EvmClient } from "./evm";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvmClient = void 0;
4
+ var evm_1 = require("./evm");
5
+ Object.defineProperty(exports, "EvmClient", { enumerable: true, get: function () { return evm_1.EvmClient; } });
@@ -0,0 +1 @@
1
+ export { SolanaClient } from "./solana";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaClient = void 0;
4
+ var solana_1 = require("./solana");
5
+ Object.defineProperty(exports, "SolanaClient", { enumerable: true, get: function () { return solana_1.SolanaClient; } });
@@ -0,0 +1,168 @@
1
+ import { SolanaClientInterface, Account, CreateAccountOptions, GetAccountOptions, ListAccountsOptions, RequestFaucetOptions, ListAccountsResult, SignatureResult, SignMessageOptions, SignTransactionOptions } from "./solana.types";
2
+ /**
3
+ * The namespace containing all Solana methods.
4
+ */
5
+ export declare class SolanaClient implements SolanaClientInterface {
6
+ /**
7
+ * Creates a new Solana account.
8
+ *
9
+ * @param {CreateAccountOptions} options - Parameters for creating the Solana account.
10
+ * @param {string} [options.name] - The name of the account.
11
+ * @param {string} [options.idempotencyKey] - An idempotency key.
12
+ *
13
+ * @returns A promise that resolves to the newly created account.
14
+ *
15
+ * @example **Without arguments**
16
+ * ```ts
17
+ * const account = await cdp.solana.createAccount();
18
+ * ```
19
+ *
20
+ * @example **With a name**
21
+ * ```ts
22
+ * const account = await cdp.solana.createAccount({ name: "MyAccount" });
23
+ * ```
24
+ *
25
+ * @example **With an idempotency key**
26
+ * ```ts
27
+ * const idempotencyKey = uuidv4();
28
+ *
29
+ * // First call
30
+ * await cdp.solana.createAccount({ idempotencyKey });
31
+ *
32
+ * // Second call with the same idempotency key will return the same account
33
+ * await cdp.solana.createAccount({ idempotencyKey });
34
+ * ```
35
+ */
36
+ createAccount(options?: CreateAccountOptions): Promise<Account>;
37
+ /**
38
+ * Gets a Solana account by its address.
39
+ *
40
+ * @param {GetAccountOptions} options - Parameters for getting the Solana account.
41
+ * Either `address` or `name` must be provided.
42
+ * If both are provided, lookup will be done by `address` and `name` will be ignored.
43
+ * @param {string} [options.address] - The address of the account.
44
+ * @param {string} [options.name] - The name of the account.
45
+ *
46
+ * @returns A promise that resolves to the account.
47
+ *
48
+ * @example **Get an account by address**
49
+ * ```ts
50
+ * const account = await cdp.solana.getAccount({
51
+ * address: "1234567890123456789012345678901234567890",
52
+ * });
53
+ * ```
54
+ *
55
+ * @example **Get an account by name**
56
+ * ```ts
57
+ * const account = await cdp.solana.getAccount({
58
+ * name: "MyAccount",
59
+ * });
60
+ * ```
61
+ */
62
+ getAccount(options: GetAccountOptions): Promise<Account>;
63
+ /**
64
+ * Lists all Solana accounts.
65
+ *
66
+ * @param {ListAccountsOptions} options - Parameters for listing the Solana accounts.
67
+ * @param {number} [options.pageSize] - The number of accounts to return.
68
+ * @param {string} [options.pageToken] - The page token to begin listing from.
69
+ * This is obtained by previous calls to this method.
70
+ *
71
+ * @returns A promise that resolves to an array of Solana account instances.
72
+ *
73
+ * @example **Without arguments**
74
+ * ```ts
75
+ * const accounts = await cdp.solana.listAccounts();
76
+ * ```
77
+ *
78
+ * @example **With pagination**
79
+ * ```ts
80
+ * let page = await cdp.solana.listAccounts();
81
+ *
82
+ * while (page.nextPageToken) {
83
+ * page = await cdp.solana.listAccounts({ pageToken: page.nextPageToken });
84
+ * }
85
+ *
86
+ * page.accounts.forEach(account => console.log(account));
87
+ * ```
88
+ * }
89
+ * ```
90
+ */
91
+ listAccounts(options?: ListAccountsOptions): Promise<ListAccountsResult>;
92
+ /**
93
+ * Requests funds from a Solana faucet.
94
+ *
95
+ * @param {RequestFaucetOptions} options - Parameters for requesting funds from the Solana faucet.
96
+ * @param {string} options.address - The address to request funds for.
97
+ * @param {string} options.token - The token to request funds for.
98
+ * @param {string} [options.idempotencyKey] - An idempotency key.
99
+ *
100
+ * @returns A promise that resolves to the transaction signature.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const signature = await cdp.solana.requestFaucet({
105
+ * address: "1234567890123456789012345678901234567890",
106
+ * token: "sol",
107
+ * });
108
+ * ```
109
+ */
110
+ requestFaucet(options: RequestFaucetOptions): Promise<SignatureResult>;
111
+ /**
112
+ * Signs a message.
113
+ *
114
+ * @param {SignMessageOptions} options - Parameters for signing the message.
115
+ * @param {string} options.address - The address to sign the message for.
116
+ * @param {string} options.message - The message to sign.
117
+ * @param {string} [options.idempotencyKey] - An idempotency key.
118
+ *
119
+ * @returns A promise that resolves to the signature.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * // Create a Solana account
124
+ * const account = await cdp.solana.createAccount();
125
+ *
126
+ * // When you want to sign a message, you can do so by address
127
+ * const signature = await cdp.solana.signMessage({
128
+ * address: account.address,
129
+ * message: "Hello, world!",
130
+ * });
131
+ * ```
132
+ */
133
+ signMessage(options: SignMessageOptions): Promise<SignatureResult>;
134
+ /**
135
+ * Signs a transaction.
136
+ *
137
+ * @param {SignTransactionOptions} options - Parameters for signing the transaction.
138
+ * @param {string} options.address - The address to sign the transaction for.
139
+ * @param {string} options.transaction - The transaction to sign.
140
+ * @param {string} [options.idempotencyKey] - An idempotency key.
141
+ *
142
+ * @returns A promise that resolves to the signature.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * // Create a Solana account
147
+ * const account = await cdp.solana.createAccount();
148
+ *
149
+ * // Add your transaction instructions here
150
+ * const transaction = new Transaction()
151
+ *
152
+ * // Make sure to set requireAllSignatures to false, since signing will be done through the API
153
+ * const serializedTransaction = transaction.serialize({
154
+ * requireAllSignatures: false,
155
+ * });
156
+ *
157
+ * // Base64 encode the serialized transaction
158
+ * const transaction = Buffer.from(serializedTransaction).toString("base64");
159
+ *
160
+ * // When you want to sign a transaction, you can do so by address and base64 encoded transaction
161
+ * const signature = await cdp.solana.signTransaction({
162
+ * address: account.address,
163
+ * transaction,
164
+ * });
165
+ * ```
166
+ */
167
+ signTransaction(options: SignTransactionOptions): Promise<SignatureResult>;
168
+ }
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaClient = void 0;
4
+ const openapi_client_1 = require("../../openapi-client");
5
+ /**
6
+ * The namespace containing all Solana methods.
7
+ */
8
+ class SolanaClient {
9
+ /**
10
+ * Creates a new Solana account.
11
+ *
12
+ * @param {CreateAccountOptions} options - Parameters for creating the Solana account.
13
+ * @param {string} [options.name] - The name of the account.
14
+ * @param {string} [options.idempotencyKey] - An idempotency key.
15
+ *
16
+ * @returns A promise that resolves to the newly created account.
17
+ *
18
+ * @example **Without arguments**
19
+ * ```ts
20
+ * const account = await cdp.solana.createAccount();
21
+ * ```
22
+ *
23
+ * @example **With a name**
24
+ * ```ts
25
+ * const account = await cdp.solana.createAccount({ name: "MyAccount" });
26
+ * ```
27
+ *
28
+ * @example **With an idempotency key**
29
+ * ```ts
30
+ * const idempotencyKey = uuidv4();
31
+ *
32
+ * // First call
33
+ * await cdp.solana.createAccount({ idempotencyKey });
34
+ *
35
+ * // Second call with the same idempotency key will return the same account
36
+ * await cdp.solana.createAccount({ idempotencyKey });
37
+ * ```
38
+ */
39
+ async createAccount(options = {}) {
40
+ return openapi_client_1.CdpOpenApiClient.createSolanaAccount(options, options.idempotencyKey);
41
+ }
42
+ /**
43
+ * Gets a Solana account by its address.
44
+ *
45
+ * @param {GetAccountOptions} options - Parameters for getting the Solana account.
46
+ * Either `address` or `name` must be provided.
47
+ * If both are provided, lookup will be done by `address` and `name` will be ignored.
48
+ * @param {string} [options.address] - The address of the account.
49
+ * @param {string} [options.name] - The name of the account.
50
+ *
51
+ * @returns A promise that resolves to the account.
52
+ *
53
+ * @example **Get an account by address**
54
+ * ```ts
55
+ * const account = await cdp.solana.getAccount({
56
+ * address: "1234567890123456789012345678901234567890",
57
+ * });
58
+ * ```
59
+ *
60
+ * @example **Get an account by name**
61
+ * ```ts
62
+ * const account = await cdp.solana.getAccount({
63
+ * name: "MyAccount",
64
+ * });
65
+ * ```
66
+ */
67
+ async getAccount(options) {
68
+ if (options.address) {
69
+ return openapi_client_1.CdpOpenApiClient.getSolanaAccount(options.address);
70
+ }
71
+ if (options.name) {
72
+ return openapi_client_1.CdpOpenApiClient.getSolanaAccountByName(options.name);
73
+ }
74
+ throw new Error("Either address or name must be provided");
75
+ }
76
+ /**
77
+ * Lists all Solana accounts.
78
+ *
79
+ * @param {ListAccountsOptions} options - Parameters for listing the Solana accounts.
80
+ * @param {number} [options.pageSize] - The number of accounts to return.
81
+ * @param {string} [options.pageToken] - The page token to begin listing from.
82
+ * This is obtained by previous calls to this method.
83
+ *
84
+ * @returns A promise that resolves to an array of Solana account instances.
85
+ *
86
+ * @example **Without arguments**
87
+ * ```ts
88
+ * const accounts = await cdp.solana.listAccounts();
89
+ * ```
90
+ *
91
+ * @example **With pagination**
92
+ * ```ts
93
+ * let page = await cdp.solana.listAccounts();
94
+ *
95
+ * while (page.nextPageToken) {
96
+ * page = await cdp.solana.listAccounts({ pageToken: page.nextPageToken });
97
+ * }
98
+ *
99
+ * page.accounts.forEach(account => console.log(account));
100
+ * ```
101
+ * }
102
+ * ```
103
+ */
104
+ async listAccounts(options = {}) {
105
+ const solAccounts = await openapi_client_1.CdpOpenApiClient.listSolanaAccounts({
106
+ pageSize: options.pageSize,
107
+ pageToken: options.pageToken,
108
+ });
109
+ return {
110
+ accounts: solAccounts.accounts,
111
+ nextPageToken: solAccounts.nextPageToken,
112
+ };
113
+ }
114
+ /**
115
+ * Requests funds from a Solana faucet.
116
+ *
117
+ * @param {RequestFaucetOptions} options - Parameters for requesting funds from the Solana faucet.
118
+ * @param {string} options.address - The address to request funds for.
119
+ * @param {string} options.token - The token to request funds for.
120
+ * @param {string} [options.idempotencyKey] - An idempotency key.
121
+ *
122
+ * @returns A promise that resolves to the transaction signature.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const signature = await cdp.solana.requestFaucet({
127
+ * address: "1234567890123456789012345678901234567890",
128
+ * token: "sol",
129
+ * });
130
+ * ```
131
+ */
132
+ async requestFaucet(options) {
133
+ const signature = await openapi_client_1.CdpOpenApiClient.requestSolanaFaucet({ address: options.address, token: options.token }, options.idempotencyKey);
134
+ return {
135
+ signature: signature.transactionSignature,
136
+ };
137
+ }
138
+ /**
139
+ * Signs a message.
140
+ *
141
+ * @param {SignMessageOptions} options - Parameters for signing the message.
142
+ * @param {string} options.address - The address to sign the message for.
143
+ * @param {string} options.message - The message to sign.
144
+ * @param {string} [options.idempotencyKey] - An idempotency key.
145
+ *
146
+ * @returns A promise that resolves to the signature.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * // Create a Solana account
151
+ * const account = await cdp.solana.createAccount();
152
+ *
153
+ * // When you want to sign a message, you can do so by address
154
+ * const signature = await cdp.solana.signMessage({
155
+ * address: account.address,
156
+ * message: "Hello, world!",
157
+ * });
158
+ * ```
159
+ */
160
+ async signMessage(options) {
161
+ return openapi_client_1.CdpOpenApiClient.signSolanaMessage(options.address, {
162
+ message: options.message,
163
+ }, options.idempotencyKey);
164
+ }
165
+ /**
166
+ * Signs a transaction.
167
+ *
168
+ * @param {SignTransactionOptions} options - Parameters for signing the transaction.
169
+ * @param {string} options.address - The address to sign the transaction for.
170
+ * @param {string} options.transaction - The transaction to sign.
171
+ * @param {string} [options.idempotencyKey] - An idempotency key.
172
+ *
173
+ * @returns A promise that resolves to the signature.
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * // Create a Solana account
178
+ * const account = await cdp.solana.createAccount();
179
+ *
180
+ * // Add your transaction instructions here
181
+ * const transaction = new Transaction()
182
+ *
183
+ * // Make sure to set requireAllSignatures to false, since signing will be done through the API
184
+ * const serializedTransaction = transaction.serialize({
185
+ * requireAllSignatures: false,
186
+ * });
187
+ *
188
+ * // Base64 encode the serialized transaction
189
+ * const transaction = Buffer.from(serializedTransaction).toString("base64");
190
+ *
191
+ * // When you want to sign a transaction, you can do so by address and base64 encoded transaction
192
+ * const signature = await cdp.solana.signTransaction({
193
+ * address: account.address,
194
+ * transaction,
195
+ * });
196
+ * ```
197
+ */
198
+ async signTransaction(options) {
199
+ const signature = await openapi_client_1.CdpOpenApiClient.signSolanaTransaction(options.address, {
200
+ transaction: options.transaction,
201
+ }, options.idempotencyKey);
202
+ return {
203
+ signature: signature.signedTransaction,
204
+ };
205
+ }
206
+ }
207
+ exports.SolanaClient = SolanaClient;