@xchainjs/xchain-solana 0.0.1
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/README.md +75 -0
- package/lib/client.d.ts +107 -0
- package/lib/const.d.ts +15 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +502 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +514 -0
- package/lib/index.js.map +1 -0
- package/lib/solana-types.d.ts +19 -0
- package/lib/types.d.ts +40 -0
- package/lib/utils.d.ts +3 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1 align="center">Solana client</h1>
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href='https://www.npmjs.com/package/@xchainjs/xchain-solana' target='_blank'>
|
|
6
|
+
<img alt="NPM Version" src="https://img.shields.io/npm/v/%40xchainjs%2Fxchain-solana" />
|
|
7
|
+
</a>
|
|
8
|
+
<a href='https://www.npmjs.com/package/@xchainjs/xchain-solana' target='_blank'>
|
|
9
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/d18m/%40xchainjs%2Fxchain-solana" />
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<br />
|
|
15
|
+
|
|
16
|
+
Client that allows to perform operations on the Solana blockchain abstracting developers from its particularities, thus allowing developers to focus on their projects. The Solana client is built on top of [@solana/web3.js](https://github.com/solana-labs/solana-web3.js) and the suite of packages developed by the [Metaplex](https://www.metaplex.com/) foundation.
|
|
17
|
+
|
|
18
|
+
If you want to read more about Solana blockchain, go to its official [web site](https://solana.com/)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
yarn add @xchainjs/xchain-solana
|
|
25
|
+
```
|
|
26
|
+
or
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm install @xchainjs/xchain-solana
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Initialization
|
|
33
|
+
|
|
34
|
+
Using the Solana client you can initialize the main class of the module in consultation mode if you do not provide any parameters, this means you could retrieve information from the blockchain and prepare transactions to sign, but you will not be able to sign transactions, or generate addresses.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Client } from '@xchainjs/xchain-solana'
|
|
38
|
+
|
|
39
|
+
const client = new Client()
|
|
40
|
+
|
|
41
|
+
// Make read operations with your client
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Otherwise, if you want to sign transactions and get the addresses you own, you will need to initialize the main class of the protocol as follows
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { Client, defaultSolanaParams } from '@xchainjs/xchain-solana'
|
|
48
|
+
|
|
49
|
+
const client = new Client({
|
|
50
|
+
phrase: 'your secret phrase',
|
|
51
|
+
...defaultSolanaParams
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Make read or write operations with your client
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Features
|
|
58
|
+
|
|
59
|
+
Thanks to the Solana client you will be able to:
|
|
60
|
+
- Get the Solana and tokens balances that an address owns
|
|
61
|
+
- Generate addresses given a secret phrase
|
|
62
|
+
- Transfer Solana and tokens to another address
|
|
63
|
+
- Get details of a transaction
|
|
64
|
+
- Get address transaction history
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Examples
|
|
69
|
+
|
|
70
|
+
You can find examples using the Solana package in the [solana](https://github.com/xchainjs/xchainjs-lib/tree/master/examples/solana) examples folder.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
More information about how to use the Solana client can be found on [documentation](https://xchainjs.gitbook.io/xchainjs/clients/xchain-solana)
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AssetInfo, BaseXChainClient, Fees, PreparedTx, TxHash, TxHistoryParams } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Address, TokenAsset } from '@xchainjs/xchain-util';
|
|
3
|
+
import { Balance, SOLClientParams, Tx, TxParams, TxsPage } from './types';
|
|
4
|
+
export declare class Client extends BaseXChainClient {
|
|
5
|
+
private explorerProviders;
|
|
6
|
+
private connection;
|
|
7
|
+
private umi;
|
|
8
|
+
constructor(params?: SOLClientParams);
|
|
9
|
+
/**
|
|
10
|
+
* Get information about the native asset of the Solana.
|
|
11
|
+
*
|
|
12
|
+
* @returns {AssetInfo} Information about the native asset.
|
|
13
|
+
*/
|
|
14
|
+
getAssetInfo(): AssetInfo;
|
|
15
|
+
/**
|
|
16
|
+
* Get the explorer URL.
|
|
17
|
+
*
|
|
18
|
+
* @returns {string} The explorer URL.
|
|
19
|
+
*/
|
|
20
|
+
getExplorerUrl(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get the explorer url for the given address.
|
|
23
|
+
*
|
|
24
|
+
* @param {Address} address
|
|
25
|
+
* @returns {string} The explorer url for the given address.
|
|
26
|
+
*/
|
|
27
|
+
getExplorerAddressUrl(address: Address): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get the explorer url for the given transaction id.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} txID
|
|
32
|
+
* @returns {string} The explorer url for the given transaction id.
|
|
33
|
+
*/
|
|
34
|
+
getExplorerTxUrl(txID: TxHash): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get the full derivation path based on the wallet index.
|
|
37
|
+
* @param {number} walletIndex The HD wallet index
|
|
38
|
+
* @returns {string} The full derivation path
|
|
39
|
+
*/
|
|
40
|
+
getFullDerivationPath(walletIndex: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get the current address asynchronously.
|
|
43
|
+
*
|
|
44
|
+
* @param {number} index The index of the address. Default 0
|
|
45
|
+
* @returns {Address} The Solana address related to the index provided.
|
|
46
|
+
* @throws {"Phrase must be provided"} Thrown if the phrase has not been set before.
|
|
47
|
+
*/
|
|
48
|
+
getAddressAsync(index?: number): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the current address synchronously.
|
|
51
|
+
* @deprecated
|
|
52
|
+
*/
|
|
53
|
+
getAddress(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Validate the given Solana address.
|
|
56
|
+
* @param {string} address Solana address to validate.
|
|
57
|
+
* @returns {boolean} `true` if the address is valid, `false` otherwise.
|
|
58
|
+
*/
|
|
59
|
+
validateAddress(address: Address): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the balance of a given address.
|
|
62
|
+
* @param {Address} address - The address to retrieve the balance for.
|
|
63
|
+
* @param {TokenAsset[]} assets - Assets to retrieve the balance for (optional).
|
|
64
|
+
* @returns {Promise<Balance[]>} An array containing the balance of the address.
|
|
65
|
+
*/
|
|
66
|
+
getBalance(address: Address, assets?: TokenAsset[]): Promise<Balance[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Get transaction fees.
|
|
69
|
+
*
|
|
70
|
+
* @param {TxParams} params - The transaction parameters.
|
|
71
|
+
* @returns {Fees} The average, fast, and fastest fees.
|
|
72
|
+
* @throws {"Params need to be passed"} Thrown if parameters are not provided.
|
|
73
|
+
*/
|
|
74
|
+
getFees(params?: TxParams): Promise<Fees>;
|
|
75
|
+
/**
|
|
76
|
+
* Get the transaction details of a given transaction ID.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} txId The transaction ID.
|
|
79
|
+
* @returns {Tx} The transaction details.
|
|
80
|
+
*/
|
|
81
|
+
getTransactionData(txId: string): Promise<Tx>;
|
|
82
|
+
getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
|
|
83
|
+
/**
|
|
84
|
+
* Transfers SOL or Solana token
|
|
85
|
+
*
|
|
86
|
+
* @param {TxParams} params The transfer options.
|
|
87
|
+
* @returns {TxHash} The transaction hash.
|
|
88
|
+
*/
|
|
89
|
+
transfer({ walletIndex, recipient, asset, amount, memo, limit, priorityFee, }: TxParams): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Broadcast a transaction to the network
|
|
92
|
+
* @param {string} txHex Raw transaction to broadcast
|
|
93
|
+
* @returns {TxHash} The hash of the transaction broadcasted
|
|
94
|
+
*/
|
|
95
|
+
broadcastTx(txHex: string): Promise<TxHash>;
|
|
96
|
+
/**
|
|
97
|
+
* Prepares a transaction for transfer.
|
|
98
|
+
*
|
|
99
|
+
* @param {TxParams&Address} params - The transfer options.
|
|
100
|
+
* @returns {Promise<PreparedTx>} The raw unsigned transaction.
|
|
101
|
+
*/
|
|
102
|
+
prepareTx({ sender, recipient, asset, amount, memo, limit, priorityFee, }: TxParams & {
|
|
103
|
+
sender: Address;
|
|
104
|
+
}): Promise<PreparedTx>;
|
|
105
|
+
private getPrivateKeyPair;
|
|
106
|
+
private parseTransaction;
|
|
107
|
+
}
|
package/lib/const.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Asset } from '@xchainjs/xchain-util';
|
|
2
|
+
import { SOLClientParams } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Solana chain symbol
|
|
5
|
+
*/
|
|
6
|
+
export declare const SOLChain: "SOL";
|
|
7
|
+
/**
|
|
8
|
+
* Solana native asset decimals
|
|
9
|
+
*/
|
|
10
|
+
export declare const SOL_DECIMALS = 9;
|
|
11
|
+
/**
|
|
12
|
+
* Solana native asset
|
|
13
|
+
*/
|
|
14
|
+
export declare const SOLAsset: Asset;
|
|
15
|
+
export declare const defaultSolanaParams: SOLClientParams;
|
package/lib/index.d.ts
ADDED