@solana/kit-plugin-airdrop 0.0.0 → 0.3.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 +22 -0
- package/README.md +58 -0
- package/dist/index.browser.cjs +32 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +30 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.node.cjs +32 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +30 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/index.react-native.mjs +30 -0
- package/dist/index.react-native.mjs.map +1 -0
- package/dist/types/index.d.ts +62 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +63 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Anza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Kit Plugins ➤ Airdrop
|
|
2
|
+
|
|
3
|
+
[![npm][npm-image]][npm-url]
|
|
4
|
+
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
5
|
+
|
|
6
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/kit-plugin-airdrop.svg?style=flat
|
|
7
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/kit-plugin-airdrop.svg?style=flat&label=%40solana%2Fkit-plugin-airdrop
|
|
8
|
+
[npm-url]: https://www.npmjs.com/package/@solana/kit-plugin-airdrop
|
|
9
|
+
|
|
10
|
+
This package provides a plugin that adds an `airdrop` helper function to your Kit client.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm install @solana/kit-plugin-airdrop
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
> [!NOTE]
|
|
19
|
+
> This package is included in the main [`@solana/kit-plugins`](../kit-plugins) package.
|
|
20
|
+
>
|
|
21
|
+
> ```sh
|
|
22
|
+
> pnpm install @solana/kit-plugins
|
|
23
|
+
> ```
|
|
24
|
+
|
|
25
|
+
## `airdrop` plugin
|
|
26
|
+
|
|
27
|
+
The `airdrop` plugin provides an `airdrop` function that allows you to request SOL airdrops to a specified account.
|
|
28
|
+
|
|
29
|
+
### Installation
|
|
30
|
+
|
|
31
|
+
In order to use the `airdrop` plugin, the client must be configured with either an RPC plugin or a LiteSVM plugin. You will get a TypeScript error if neither is provided before using the `airdrop` plugin.
|
|
32
|
+
|
|
33
|
+
#### Using an RPC
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createEmptyClient } from '@solana/kit';
|
|
37
|
+
import { airdrop, localhostRpc } from '@solana/kit-plugins';
|
|
38
|
+
|
|
39
|
+
const client = createEmptyClient().use(localhostRpc()).use(airdrop());
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Note that you will get a TypeScript error when using the `rpc` plugin with a mainnet URL such as `mainnet("https://api.mainnet-beta.solana.com")`, because airdrop RPC methods are not supported on mainnet.
|
|
43
|
+
|
|
44
|
+
#### Using a LiteSVM instance
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createEmptyClient } from '@solana/kit';
|
|
48
|
+
import { airdrop, litesvm } from '@solana/kit-plugins';
|
|
49
|
+
|
|
50
|
+
const client = createEmptyClient().use(litesvm()).use(airdrop());
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Features
|
|
54
|
+
|
|
55
|
+
- `airdrop`: An asynchronous helper function that airdrops a specified amount of lamports to a given address.
|
|
56
|
+
```ts
|
|
57
|
+
client.airdrop(address('HQVxiMVDoV9jzG4tpoxmDZsNfWvaHXm8DGGv93Gka75v'), lamports(1_000_000_000n));
|
|
58
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var kit = require('@solana/kit');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
function airdrop() {
|
|
7
|
+
return (client) => {
|
|
8
|
+
if ("svm" in client) {
|
|
9
|
+
const airdrop3 = (address, amount) => {
|
|
10
|
+
client.svm.airdrop(address, amount);
|
|
11
|
+
return Promise.resolve();
|
|
12
|
+
};
|
|
13
|
+
return { ...client, airdrop: airdrop3 };
|
|
14
|
+
}
|
|
15
|
+
const airdropInternal = kit.airdropFactory({
|
|
16
|
+
rpc: client.rpc,
|
|
17
|
+
rpcSubscriptions: client.rpcSubscriptions
|
|
18
|
+
});
|
|
19
|
+
const airdrop2 = (address, amount, abortSignal) => airdropInternal({
|
|
20
|
+
abortSignal,
|
|
21
|
+
commitment: "confirmed",
|
|
22
|
+
lamports: amount,
|
|
23
|
+
recipientAddress: address
|
|
24
|
+
}).then(() => {
|
|
25
|
+
});
|
|
26
|
+
return { ...client, airdrop: airdrop2 };
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.airdrop = airdrop;
|
|
31
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
32
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["airdrop","airdropFactory"],"mappings":";;;;;AA0DO,SAAS,OAAA,GAAU;AACtB,EAAA,OAAO,CAAsC,MAAA,KAAgD;AACzF,IAAA,IAAI,SAAS,MAAA,EAAQ;AACjB,MAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,KAAW;AAClD,QAAA,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,EAAS,MAAM,CAAA;AAClC,QAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,MAC3B,CAAA;AACA,MAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,IAChC;AACA,IAAA,MAAM,kBAAkBC,kBAAA,CAAe;AAAA,MACnC,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,kBAAkB,MAAA,CAAO;AAAA,KAC5B,CAAA;AACD,IAAA,MAAMD,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,EAAQ,gBAC/C,eAAA,CAAgB;AAAA,MACZ,WAAA;AAAA,MACA,UAAA,EAAY,WAAA;AAAA,MACZ,QAAA,EAAU,MAAA;AAAA,MACV,gBAAA,EAAkB;AAAA,KACrB,CAAA,CAAE,IAAA,CAAK,MAAM;AAAA,IAAC,CAAC,CAAA;AACpB,IAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,EAChC,CAAA;AACJ","file":"index.browser.cjs","sourcesContent":["import { Address, airdropFactory, Lamports } from '@solana/kit';\n\ntype LiteSVMClient = {\n svm: { airdrop: (address: Address, lamports: Lamports) => unknown };\n};\ntype RpcClient = {\n rpc: Parameters<typeof airdropFactory>[0]['rpc'];\n rpcSubscriptions: Parameters<typeof airdropFactory>[0]['rpcSubscriptions'];\n};\n\n/**\n * Function type for the `airdrop` method added to the client.\n *\n * @param address - The address to which the airdrop will be sent.\n * @param amount - The amount of lamports to airdrop.\n * @param abortSignal - Optional signal to abort the airdrop operation.\n */\nexport type AirdropFunction = (address: Address, amount: Lamports, abortSignal?: AbortSignal) => Promise<void>;\n\n/**\n * A plugin that adds an `airdrop` method to the client.\n *\n * This will use the LiteSVM's internal airdrop method if the\n * client has LiteSVM installed. Otherwise, it will rely on the\n * `Rpc` and `RpcSubscriptions` clients to perform the airdrop.\n *\n * @example\n * RPC-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, localhostRpc } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a localhost RPC.\n * const client = createEmptyClient()\n * .use(localhostRpc())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @example\n * LiteSVM-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, litesvm } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a LiteSVM instance.\n * const client = createEmptyClient()\n * .use(litesvm())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @see {@link AirdropFunction}\n */\nexport function airdrop() {\n return <T extends LiteSVMClient | RpcClient>(client: T): T & { airdrop: AirdropFunction } => {\n if ('svm' in client) {\n const airdrop: AirdropFunction = (address, amount) => {\n client.svm.airdrop(address, amount);\n return Promise.resolve();\n };\n return { ...client, airdrop };\n }\n const airdropInternal = airdropFactory({\n rpc: client.rpc,\n rpcSubscriptions: client.rpcSubscriptions,\n });\n const airdrop: AirdropFunction = (address, amount, abortSignal) =>\n airdropInternal({\n abortSignal,\n commitment: 'confirmed',\n lamports: amount,\n recipientAddress: address,\n }).then(() => {});\n return { ...client, airdrop };\n };\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { airdropFactory } from '@solana/kit';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function airdrop() {
|
|
5
|
+
return (client) => {
|
|
6
|
+
if ("svm" in client) {
|
|
7
|
+
const airdrop3 = (address, amount) => {
|
|
8
|
+
client.svm.airdrop(address, amount);
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
};
|
|
11
|
+
return { ...client, airdrop: airdrop3 };
|
|
12
|
+
}
|
|
13
|
+
const airdropInternal = airdropFactory({
|
|
14
|
+
rpc: client.rpc,
|
|
15
|
+
rpcSubscriptions: client.rpcSubscriptions
|
|
16
|
+
});
|
|
17
|
+
const airdrop2 = (address, amount, abortSignal) => airdropInternal({
|
|
18
|
+
abortSignal,
|
|
19
|
+
commitment: "confirmed",
|
|
20
|
+
lamports: amount,
|
|
21
|
+
recipientAddress: address
|
|
22
|
+
}).then(() => {
|
|
23
|
+
});
|
|
24
|
+
return { ...client, airdrop: airdrop2 };
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { airdrop };
|
|
29
|
+
//# sourceMappingURL=index.browser.mjs.map
|
|
30
|
+
//# sourceMappingURL=index.browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["airdrop"],"mappings":";;;AA0DO,SAAS,OAAA,GAAU;AACtB,EAAA,OAAO,CAAsC,MAAA,KAAgD;AACzF,IAAA,IAAI,SAAS,MAAA,EAAQ;AACjB,MAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,KAAW;AAClD,QAAA,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,EAAS,MAAM,CAAA;AAClC,QAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,MAC3B,CAAA;AACA,MAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,IAChC;AACA,IAAA,MAAM,kBAAkB,cAAA,CAAe;AAAA,MACnC,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,kBAAkB,MAAA,CAAO;AAAA,KAC5B,CAAA;AACD,IAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,EAAQ,gBAC/C,eAAA,CAAgB;AAAA,MACZ,WAAA;AAAA,MACA,UAAA,EAAY,WAAA;AAAA,MACZ,QAAA,EAAU,MAAA;AAAA,MACV,gBAAA,EAAkB;AAAA,KACrB,CAAA,CAAE,IAAA,CAAK,MAAM;AAAA,IAAC,CAAC,CAAA;AACpB,IAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,EAChC,CAAA;AACJ","file":"index.browser.mjs","sourcesContent":["import { Address, airdropFactory, Lamports } from '@solana/kit';\n\ntype LiteSVMClient = {\n svm: { airdrop: (address: Address, lamports: Lamports) => unknown };\n};\ntype RpcClient = {\n rpc: Parameters<typeof airdropFactory>[0]['rpc'];\n rpcSubscriptions: Parameters<typeof airdropFactory>[0]['rpcSubscriptions'];\n};\n\n/**\n * Function type for the `airdrop` method added to the client.\n *\n * @param address - The address to which the airdrop will be sent.\n * @param amount - The amount of lamports to airdrop.\n * @param abortSignal - Optional signal to abort the airdrop operation.\n */\nexport type AirdropFunction = (address: Address, amount: Lamports, abortSignal?: AbortSignal) => Promise<void>;\n\n/**\n * A plugin that adds an `airdrop` method to the client.\n *\n * This will use the LiteSVM's internal airdrop method if the\n * client has LiteSVM installed. Otherwise, it will rely on the\n * `Rpc` and `RpcSubscriptions` clients to perform the airdrop.\n *\n * @example\n * RPC-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, localhostRpc } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a localhost RPC.\n * const client = createEmptyClient()\n * .use(localhostRpc())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @example\n * LiteSVM-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, litesvm } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a LiteSVM instance.\n * const client = createEmptyClient()\n * .use(litesvm())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @see {@link AirdropFunction}\n */\nexport function airdrop() {\n return <T extends LiteSVMClient | RpcClient>(client: T): T & { airdrop: AirdropFunction } => {\n if ('svm' in client) {\n const airdrop: AirdropFunction = (address, amount) => {\n client.svm.airdrop(address, amount);\n return Promise.resolve();\n };\n return { ...client, airdrop };\n }\n const airdropInternal = airdropFactory({\n rpc: client.rpc,\n rpcSubscriptions: client.rpcSubscriptions,\n });\n const airdrop: AirdropFunction = (address, amount, abortSignal) =>\n airdropInternal({\n abortSignal,\n commitment: 'confirmed',\n lamports: amount,\n recipientAddress: address,\n }).then(() => {});\n return { ...client, airdrop };\n };\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var kit = require('@solana/kit');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
function airdrop() {
|
|
7
|
+
return (client) => {
|
|
8
|
+
if ("svm" in client) {
|
|
9
|
+
const airdrop3 = (address, amount) => {
|
|
10
|
+
client.svm.airdrop(address, amount);
|
|
11
|
+
return Promise.resolve();
|
|
12
|
+
};
|
|
13
|
+
return { ...client, airdrop: airdrop3 };
|
|
14
|
+
}
|
|
15
|
+
const airdropInternal = kit.airdropFactory({
|
|
16
|
+
rpc: client.rpc,
|
|
17
|
+
rpcSubscriptions: client.rpcSubscriptions
|
|
18
|
+
});
|
|
19
|
+
const airdrop2 = (address, amount, abortSignal) => airdropInternal({
|
|
20
|
+
abortSignal,
|
|
21
|
+
commitment: "confirmed",
|
|
22
|
+
lamports: amount,
|
|
23
|
+
recipientAddress: address
|
|
24
|
+
}).then(() => {
|
|
25
|
+
});
|
|
26
|
+
return { ...client, airdrop: airdrop2 };
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.airdrop = airdrop;
|
|
31
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
32
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["airdrop","airdropFactory"],"mappings":";;;;;AA0DO,SAAS,OAAA,GAAU;AACtB,EAAA,OAAO,CAAsC,MAAA,KAAgD;AACzF,IAAA,IAAI,SAAS,MAAA,EAAQ;AACjB,MAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,KAAW;AAClD,QAAA,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,EAAS,MAAM,CAAA;AAClC,QAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,MAC3B,CAAA;AACA,MAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,IAChC;AACA,IAAA,MAAM,kBAAkBC,kBAAA,CAAe;AAAA,MACnC,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,kBAAkB,MAAA,CAAO;AAAA,KAC5B,CAAA;AACD,IAAA,MAAMD,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,EAAQ,gBAC/C,eAAA,CAAgB;AAAA,MACZ,WAAA;AAAA,MACA,UAAA,EAAY,WAAA;AAAA,MACZ,QAAA,EAAU,MAAA;AAAA,MACV,gBAAA,EAAkB;AAAA,KACrB,CAAA,CAAE,IAAA,CAAK,MAAM;AAAA,IAAC,CAAC,CAAA;AACpB,IAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,EAChC,CAAA;AACJ","file":"index.node.cjs","sourcesContent":["import { Address, airdropFactory, Lamports } from '@solana/kit';\n\ntype LiteSVMClient = {\n svm: { airdrop: (address: Address, lamports: Lamports) => unknown };\n};\ntype RpcClient = {\n rpc: Parameters<typeof airdropFactory>[0]['rpc'];\n rpcSubscriptions: Parameters<typeof airdropFactory>[0]['rpcSubscriptions'];\n};\n\n/**\n * Function type for the `airdrop` method added to the client.\n *\n * @param address - The address to which the airdrop will be sent.\n * @param amount - The amount of lamports to airdrop.\n * @param abortSignal - Optional signal to abort the airdrop operation.\n */\nexport type AirdropFunction = (address: Address, amount: Lamports, abortSignal?: AbortSignal) => Promise<void>;\n\n/**\n * A plugin that adds an `airdrop` method to the client.\n *\n * This will use the LiteSVM's internal airdrop method if the\n * client has LiteSVM installed. Otherwise, it will rely on the\n * `Rpc` and `RpcSubscriptions` clients to perform the airdrop.\n *\n * @example\n * RPC-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, localhostRpc } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a localhost RPC.\n * const client = createEmptyClient()\n * .use(localhostRpc())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @example\n * LiteSVM-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, litesvm } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a LiteSVM instance.\n * const client = createEmptyClient()\n * .use(litesvm())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @see {@link AirdropFunction}\n */\nexport function airdrop() {\n return <T extends LiteSVMClient | RpcClient>(client: T): T & { airdrop: AirdropFunction } => {\n if ('svm' in client) {\n const airdrop: AirdropFunction = (address, amount) => {\n client.svm.airdrop(address, amount);\n return Promise.resolve();\n };\n return { ...client, airdrop };\n }\n const airdropInternal = airdropFactory({\n rpc: client.rpc,\n rpcSubscriptions: client.rpcSubscriptions,\n });\n const airdrop: AirdropFunction = (address, amount, abortSignal) =>\n airdropInternal({\n abortSignal,\n commitment: 'confirmed',\n lamports: amount,\n recipientAddress: address,\n }).then(() => {});\n return { ...client, airdrop };\n };\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { airdropFactory } from '@solana/kit';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function airdrop() {
|
|
5
|
+
return (client) => {
|
|
6
|
+
if ("svm" in client) {
|
|
7
|
+
const airdrop3 = (address, amount) => {
|
|
8
|
+
client.svm.airdrop(address, amount);
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
};
|
|
11
|
+
return { ...client, airdrop: airdrop3 };
|
|
12
|
+
}
|
|
13
|
+
const airdropInternal = airdropFactory({
|
|
14
|
+
rpc: client.rpc,
|
|
15
|
+
rpcSubscriptions: client.rpcSubscriptions
|
|
16
|
+
});
|
|
17
|
+
const airdrop2 = (address, amount, abortSignal) => airdropInternal({
|
|
18
|
+
abortSignal,
|
|
19
|
+
commitment: "confirmed",
|
|
20
|
+
lamports: amount,
|
|
21
|
+
recipientAddress: address
|
|
22
|
+
}).then(() => {
|
|
23
|
+
});
|
|
24
|
+
return { ...client, airdrop: airdrop2 };
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { airdrop };
|
|
29
|
+
//# sourceMappingURL=index.node.mjs.map
|
|
30
|
+
//# sourceMappingURL=index.node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["airdrop"],"mappings":";;;AA0DO,SAAS,OAAA,GAAU;AACtB,EAAA,OAAO,CAAsC,MAAA,KAAgD;AACzF,IAAA,IAAI,SAAS,MAAA,EAAQ;AACjB,MAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,KAAW;AAClD,QAAA,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,EAAS,MAAM,CAAA;AAClC,QAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,MAC3B,CAAA;AACA,MAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,IAChC;AACA,IAAA,MAAM,kBAAkB,cAAA,CAAe;AAAA,MACnC,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,kBAAkB,MAAA,CAAO;AAAA,KAC5B,CAAA;AACD,IAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,EAAQ,gBAC/C,eAAA,CAAgB;AAAA,MACZ,WAAA;AAAA,MACA,UAAA,EAAY,WAAA;AAAA,MACZ,QAAA,EAAU,MAAA;AAAA,MACV,gBAAA,EAAkB;AAAA,KACrB,CAAA,CAAE,IAAA,CAAK,MAAM;AAAA,IAAC,CAAC,CAAA;AACpB,IAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,EAChC,CAAA;AACJ","file":"index.node.mjs","sourcesContent":["import { Address, airdropFactory, Lamports } from '@solana/kit';\n\ntype LiteSVMClient = {\n svm: { airdrop: (address: Address, lamports: Lamports) => unknown };\n};\ntype RpcClient = {\n rpc: Parameters<typeof airdropFactory>[0]['rpc'];\n rpcSubscriptions: Parameters<typeof airdropFactory>[0]['rpcSubscriptions'];\n};\n\n/**\n * Function type for the `airdrop` method added to the client.\n *\n * @param address - The address to which the airdrop will be sent.\n * @param amount - The amount of lamports to airdrop.\n * @param abortSignal - Optional signal to abort the airdrop operation.\n */\nexport type AirdropFunction = (address: Address, amount: Lamports, abortSignal?: AbortSignal) => Promise<void>;\n\n/**\n * A plugin that adds an `airdrop` method to the client.\n *\n * This will use the LiteSVM's internal airdrop method if the\n * client has LiteSVM installed. Otherwise, it will rely on the\n * `Rpc` and `RpcSubscriptions` clients to perform the airdrop.\n *\n * @example\n * RPC-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, localhostRpc } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a localhost RPC.\n * const client = createEmptyClient()\n * .use(localhostRpc())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @example\n * LiteSVM-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, litesvm } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a LiteSVM instance.\n * const client = createEmptyClient()\n * .use(litesvm())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @see {@link AirdropFunction}\n */\nexport function airdrop() {\n return <T extends LiteSVMClient | RpcClient>(client: T): T & { airdrop: AirdropFunction } => {\n if ('svm' in client) {\n const airdrop: AirdropFunction = (address, amount) => {\n client.svm.airdrop(address, amount);\n return Promise.resolve();\n };\n return { ...client, airdrop };\n }\n const airdropInternal = airdropFactory({\n rpc: client.rpc,\n rpcSubscriptions: client.rpcSubscriptions,\n });\n const airdrop: AirdropFunction = (address, amount, abortSignal) =>\n airdropInternal({\n abortSignal,\n commitment: 'confirmed',\n lamports: amount,\n recipientAddress: address,\n }).then(() => {});\n return { ...client, airdrop };\n };\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { airdropFactory } from '@solana/kit';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function airdrop() {
|
|
5
|
+
return (client) => {
|
|
6
|
+
if ("svm" in client) {
|
|
7
|
+
const airdrop3 = (address, amount) => {
|
|
8
|
+
client.svm.airdrop(address, amount);
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
};
|
|
11
|
+
return { ...client, airdrop: airdrop3 };
|
|
12
|
+
}
|
|
13
|
+
const airdropInternal = airdropFactory({
|
|
14
|
+
rpc: client.rpc,
|
|
15
|
+
rpcSubscriptions: client.rpcSubscriptions
|
|
16
|
+
});
|
|
17
|
+
const airdrop2 = (address, amount, abortSignal) => airdropInternal({
|
|
18
|
+
abortSignal,
|
|
19
|
+
commitment: "confirmed",
|
|
20
|
+
lamports: amount,
|
|
21
|
+
recipientAddress: address
|
|
22
|
+
}).then(() => {
|
|
23
|
+
});
|
|
24
|
+
return { ...client, airdrop: airdrop2 };
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { airdrop };
|
|
29
|
+
//# sourceMappingURL=index.react-native.mjs.map
|
|
30
|
+
//# sourceMappingURL=index.react-native.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["airdrop"],"mappings":";;;AA0DO,SAAS,OAAA,GAAU;AACtB,EAAA,OAAO,CAAsC,MAAA,KAAgD;AACzF,IAAA,IAAI,SAAS,MAAA,EAAQ;AACjB,MAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,KAAW;AAClD,QAAA,MAAA,CAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,EAAS,MAAM,CAAA;AAClC,QAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,MAC3B,CAAA;AACA,MAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,IAChC;AACA,IAAA,MAAM,kBAAkB,cAAA,CAAe;AAAA,MACnC,KAAK,MAAA,CAAO,GAAA;AAAA,MACZ,kBAAkB,MAAA,CAAO;AAAA,KAC5B,CAAA;AACD,IAAA,MAAMA,QAAAA,GAA2B,CAAC,OAAA,EAAS,MAAA,EAAQ,gBAC/C,eAAA,CAAgB;AAAA,MACZ,WAAA;AAAA,MACA,UAAA,EAAY,WAAA;AAAA,MACZ,QAAA,EAAU,MAAA;AAAA,MACV,gBAAA,EAAkB;AAAA,KACrB,CAAA,CAAE,IAAA,CAAK,MAAM;AAAA,IAAC,CAAC,CAAA;AACpB,IAAA,OAAO,EAAE,GAAG,MAAA,EAAQ,OAAA,EAAAA,QAAAA,EAAQ;AAAA,EAChC,CAAA;AACJ","file":"index.react-native.mjs","sourcesContent":["import { Address, airdropFactory, Lamports } from '@solana/kit';\n\ntype LiteSVMClient = {\n svm: { airdrop: (address: Address, lamports: Lamports) => unknown };\n};\ntype RpcClient = {\n rpc: Parameters<typeof airdropFactory>[0]['rpc'];\n rpcSubscriptions: Parameters<typeof airdropFactory>[0]['rpcSubscriptions'];\n};\n\n/**\n * Function type for the `airdrop` method added to the client.\n *\n * @param address - The address to which the airdrop will be sent.\n * @param amount - The amount of lamports to airdrop.\n * @param abortSignal - Optional signal to abort the airdrop operation.\n */\nexport type AirdropFunction = (address: Address, amount: Lamports, abortSignal?: AbortSignal) => Promise<void>;\n\n/**\n * A plugin that adds an `airdrop` method to the client.\n *\n * This will use the LiteSVM's internal airdrop method if the\n * client has LiteSVM installed. Otherwise, it will rely on the\n * `Rpc` and `RpcSubscriptions` clients to perform the airdrop.\n *\n * @example\n * RPC-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, localhostRpc } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a localhost RPC.\n * const client = createEmptyClient()\n * .use(localhostRpc())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @example\n * LiteSVM-based airdrop.\n * ```ts\n * import { createEmptyClient } from '@solana/kit';\n * import { airdrop, litesvm } from '@solana/kit-plugins';\n *\n * // Install the airdrop plugin using a LiteSVM instance.\n * const client = createEmptyClient()\n * .use(litesvm())\n * .use(airdrop());\n *\n * // Use the airdrop method.\n * client.airdrop(myAddress, lamports(1_000_000_000n));\n * ```\n *\n * @see {@link AirdropFunction}\n */\nexport function airdrop() {\n return <T extends LiteSVMClient | RpcClient>(client: T): T & { airdrop: AirdropFunction } => {\n if ('svm' in client) {\n const airdrop: AirdropFunction = (address, amount) => {\n client.svm.airdrop(address, amount);\n return Promise.resolve();\n };\n return { ...client, airdrop };\n }\n const airdropInternal = airdropFactory({\n rpc: client.rpc,\n rpcSubscriptions: client.rpcSubscriptions,\n });\n const airdrop: AirdropFunction = (address, amount, abortSignal) =>\n airdropInternal({\n abortSignal,\n commitment: 'confirmed',\n lamports: amount,\n recipientAddress: address,\n }).then(() => {});\n return { ...client, airdrop };\n };\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Address, airdropFactory, Lamports } from '@solana/kit';
|
|
2
|
+
type LiteSVMClient = {
|
|
3
|
+
svm: {
|
|
4
|
+
airdrop: (address: Address, lamports: Lamports) => unknown;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
type RpcClient = {
|
|
8
|
+
rpc: Parameters<typeof airdropFactory>[0]['rpc'];
|
|
9
|
+
rpcSubscriptions: Parameters<typeof airdropFactory>[0]['rpcSubscriptions'];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Function type for the `airdrop` method added to the client.
|
|
13
|
+
*
|
|
14
|
+
* @param address - The address to which the airdrop will be sent.
|
|
15
|
+
* @param amount - The amount of lamports to airdrop.
|
|
16
|
+
* @param abortSignal - Optional signal to abort the airdrop operation.
|
|
17
|
+
*/
|
|
18
|
+
export type AirdropFunction = (address: Address, amount: Lamports, abortSignal?: AbortSignal) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* A plugin that adds an `airdrop` method to the client.
|
|
21
|
+
*
|
|
22
|
+
* This will use the LiteSVM's internal airdrop method if the
|
|
23
|
+
* client has LiteSVM installed. Otherwise, it will rely on the
|
|
24
|
+
* `Rpc` and `RpcSubscriptions` clients to perform the airdrop.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* RPC-based airdrop.
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { createEmptyClient } from '@solana/kit';
|
|
30
|
+
* import { airdrop, localhostRpc } from '@solana/kit-plugins';
|
|
31
|
+
*
|
|
32
|
+
* // Install the airdrop plugin using a localhost RPC.
|
|
33
|
+
* const client = createEmptyClient()
|
|
34
|
+
* .use(localhostRpc())
|
|
35
|
+
* .use(airdrop());
|
|
36
|
+
*
|
|
37
|
+
* // Use the airdrop method.
|
|
38
|
+
* client.airdrop(myAddress, lamports(1_000_000_000n));
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* LiteSVM-based airdrop.
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { createEmptyClient } from '@solana/kit';
|
|
45
|
+
* import { airdrop, litesvm } from '@solana/kit-plugins';
|
|
46
|
+
*
|
|
47
|
+
* // Install the airdrop plugin using a LiteSVM instance.
|
|
48
|
+
* const client = createEmptyClient()
|
|
49
|
+
* .use(litesvm())
|
|
50
|
+
* .use(airdrop());
|
|
51
|
+
*
|
|
52
|
+
* // Use the airdrop method.
|
|
53
|
+
* client.airdrop(myAddress, lamports(1_000_000_000n));
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @see {@link AirdropFunction}
|
|
57
|
+
*/
|
|
58
|
+
export declare function airdrop(): <T extends LiteSVMClient | RpcClient>(client: T) => T & {
|
|
59
|
+
airdrop: AirdropFunction;
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEhE,KAAK,aAAa,GAAG;IACjB,GAAG,EAAE;QAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAA;KAAE,CAAC;CACvE,CAAC;AACF,KAAK,SAAS,GAAG;IACb,GAAG,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACjD,gBAAgB,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;CAC9E,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,OAAO,KACX,CAAC,SAAS,aAAa,GAAG,SAAS,EAAE,QAAQ,CAAC,KAAG,CAAC,GAAG;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,CAqB5F"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/kit-plugin-airdrop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Airdrop helpers for Kit clients",
|
|
5
|
+
"exports": {
|
|
6
|
+
"types": "./dist/types/index.d.ts",
|
|
7
|
+
"react-native": "./dist/index.react-native.mjs",
|
|
8
|
+
"browser": {
|
|
9
|
+
"import": "./dist/index.browser.mjs",
|
|
10
|
+
"require": "./dist/index.browser.cjs"
|
|
11
|
+
},
|
|
12
|
+
"node": {
|
|
13
|
+
"import": "./dist/index.node.mjs",
|
|
14
|
+
"require": "./dist/index.node.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"browser": {
|
|
18
|
+
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
|
19
|
+
"./dist/index.node.mjs": "./dist/index.browser.mjs"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.node.cjs",
|
|
22
|
+
"module": "./dist/index.node.mjs",
|
|
23
|
+
"react-native": "./dist/index.react-native.mjs",
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"type": "commonjs",
|
|
26
|
+
"files": [
|
|
27
|
+
"./dist/types",
|
|
28
|
+
"./dist/index.*"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"keywords": [
|
|
32
|
+
"solana",
|
|
33
|
+
"kit",
|
|
34
|
+
"plugin",
|
|
35
|
+
"airdrop"
|
|
36
|
+
],
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@solana/kit": "^6.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@solana/kit-plugin-litesvm": "0.3.0",
|
|
42
|
+
"@solana/kit-plugin-rpc": "0.3.0"
|
|
10
43
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/anza-xyz/kit-plugins"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "http://github.com/anza-xyz/kit-plugins/issues"
|
|
51
|
+
},
|
|
52
|
+
"browserslist": [
|
|
53
|
+
"supports bigint and not dead",
|
|
54
|
+
"maintained node versions"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
|
|
58
|
+
"dev": "vitest --project node",
|
|
59
|
+
"lint": "eslint . && prettier --check .",
|
|
60
|
+
"lint:fix": "eslint --fix . && prettier --write .",
|
|
61
|
+
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:unit",
|
|
62
|
+
"test:treeshakability": "for file in dist/index.*.mjs; do agadoo $file; done",
|
|
63
|
+
"test:types": "tsc --noEmit",
|
|
64
|
+
"test:unit": "vitest run"
|
|
65
|
+
}
|
|
66
|
+
}
|