@xchainjs/xchain-radix 0.1.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 +213 -0
- package/lib/client.d.ts +148 -0
- package/lib/const.d.ts +32 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +14644 -0
- package/lib/index.js +14667 -0
- package/lib/types/radix.d.ts +19 -0
- package/lib/utils.d.ts +5 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# `@xchainjs/xchain-radix`
|
|
2
|
+
|
|
3
|
+
Radix module for XChainJS clients
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
6
|
+
|
|
7
|
+
- `client` - Custom client for communicating with the Radix Chain by using the [radix-engine-toolkit](https://github.com/radixdlt/typescript-radix-engine-toolkit/tree/main) and the [radix gateway api](https://radix-babylon-gateway-api.redoc.ly/)
|
|
8
|
+
|
|
9
|
+
- `types` - Typescript type defintions used by the client on top of the types defined by the [Typescript Gateway API SDK](https://www.npmjs.com/package/@radixdlt/babylon-gateway-api-sdk)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
yarn add @xchainjs/xchain-radix
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Fund an account in testnet
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
yarn fund account_address
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
### Creating a radix client
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
import { Network, XChainClientParams } from '@xchainjs/xchain-client'
|
|
29
|
+
import { Client } from '@xchainjs/xchain-radix'
|
|
30
|
+
|
|
31
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
32
|
+
const params: XChainClientParams = {
|
|
33
|
+
network: Network.Testnet,
|
|
34
|
+
phrase: phrase,
|
|
35
|
+
feeBounds: { lower: 1, upper: 5 },
|
|
36
|
+
}
|
|
37
|
+
const client = new Client(params, 'Ed25519')
|
|
38
|
+
console.log(client.getAssetInfo())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Creating a transaction
|
|
42
|
+
|
|
43
|
+
There are two methods related to creating transactions: prepareTx and transfer
|
|
44
|
+
The first one creates a raw unsigned transaction (it doesn't submit the transaction). The
|
|
45
|
+
second one submits the transaction to the ledger
|
|
46
|
+
|
|
47
|
+
#### prepareTx
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
import { Network, TxParams, XChainClientParams } from '@xchainjs/xchain-client'
|
|
51
|
+
import { Client, XrdAssetStokenet } from '@xchainjs/xchain-radix'
|
|
52
|
+
import { baseAmount } from '@xchainjs/xchain-util/lib'
|
|
53
|
+
|
|
54
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
55
|
+
const params: XChainClientParams = {
|
|
56
|
+
network: Network.Testnet,
|
|
57
|
+
phrase: phrase,
|
|
58
|
+
feeBounds: { lower: 1, upper: 5 },
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
const client = new Client(params, 'Ed25519')
|
|
63
|
+
|
|
64
|
+
const txParams: TxParams = {
|
|
65
|
+
asset: XrdAssetStokenet,
|
|
66
|
+
amount: baseAmount(1),
|
|
67
|
+
recipient: 'account_tdx_2_129wjagjzxltd0clr3q4z7hqpw5cc7weh9trs4e9k3zfwqpj636e5zf',
|
|
68
|
+
memo: 'test',
|
|
69
|
+
}
|
|
70
|
+
const preparedTx = await client.prepareTx(txParams)
|
|
71
|
+
console.log(preparedTx)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch(console.error)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### transfer
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
import { Network, TxParams, XChainClientParams } from '@xchainjs/xchain-client'
|
|
81
|
+
import { Client, XrdAssetStokenet } from '@xchainjs/xchain-radix'
|
|
82
|
+
import { baseAmount } from '@xchainjs/xchain-util/lib'
|
|
83
|
+
|
|
84
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
85
|
+
const params: XChainClientParams = {
|
|
86
|
+
network: Network.Testnet,
|
|
87
|
+
phrase: phrase,
|
|
88
|
+
feeBounds: { lower: 1, upper: 5 },
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function main() {
|
|
92
|
+
const client = new Client(params, 'Ed25519')
|
|
93
|
+
|
|
94
|
+
const txParams: TxParams = {
|
|
95
|
+
asset: XrdAssetStokenet,
|
|
96
|
+
amount: baseAmount(1),
|
|
97
|
+
recipient: 'account_tdx_2_129wjagjzxltd0clr3q4z7hqpw5cc7weh9trs4e9k3zfwqpj636e5zf',
|
|
98
|
+
memo: 'test',
|
|
99
|
+
}
|
|
100
|
+
const transactionId = await client.transfer(txParams)
|
|
101
|
+
console.log(transactionId)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
main().catch(console.error)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Getting a transaction data
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
import { Network, Tx, TxParams, XChainClientParams } from '@xchainjs/xchain-client/lib'
|
|
111
|
+
import { Client } from '@xchainjs/xchain-radix'
|
|
112
|
+
import { XrdAsset } from '@xchainjs/xchain-radix/src/const'
|
|
113
|
+
import { baseAmount } from '@xchainjs/xchain-util'
|
|
114
|
+
|
|
115
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
116
|
+
const params: XChainClientParams = {
|
|
117
|
+
network: Network.Mainnet,
|
|
118
|
+
phrase: phrase,
|
|
119
|
+
}
|
|
120
|
+
const client = new Client(params, 'Ed25519')
|
|
121
|
+
|
|
122
|
+
const txParams: TxParams = {
|
|
123
|
+
asset: XrdAsset,
|
|
124
|
+
amount: baseAmount(1000),
|
|
125
|
+
recipient: 'account_rdx169yt0y36etavnnxp4du5ekn7qq8thuls750q6frq5xw8gfq52dhxhg',
|
|
126
|
+
}
|
|
127
|
+
const transferTransaction = await radixClient.transfer(txParams)
|
|
128
|
+
const transaction: Tx = await radixClient.getTransactionData(transferTransaction)
|
|
129
|
+
console.log(transaction)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Getting balances
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
import { Balance, Network, XChainClientParams } from '@xchainjs/xchain-client/lib'
|
|
136
|
+
import { Client } from '@xchainjs/xchain-radix'
|
|
137
|
+
import { Asset } from '@xchainjs/xchain-util/lib'
|
|
138
|
+
|
|
139
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
140
|
+
const params: XChainClientParams = {
|
|
141
|
+
network: Network.Testnet,
|
|
142
|
+
phrase: phrase,
|
|
143
|
+
feeBounds: { lower: 1, upper: 5 },
|
|
144
|
+
}
|
|
145
|
+
const assets: Asset[] = [
|
|
146
|
+
{
|
|
147
|
+
symbol: 'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd',
|
|
148
|
+
ticker: 'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd',
|
|
149
|
+
chain: 'radix',
|
|
150
|
+
synth: false,
|
|
151
|
+
},
|
|
152
|
+
]
|
|
153
|
+
const balances: Balance[] = await radixClient.getBalance(
|
|
154
|
+
'account_rdx16x47guzq44lmplg0ykfn2eltwt5wweylpuupstsxnfm8lgva7tdg2w',
|
|
155
|
+
assets,
|
|
156
|
+
)
|
|
157
|
+
console.log(balances)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Getting fees
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
import { Fees, Network, XChainClientParams } from '@xchainjs/xchain-client/lib'
|
|
164
|
+
import { Client } from '@xchainjs/xchain-radix'
|
|
165
|
+
|
|
166
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
167
|
+
const params: XChainClientParams = {
|
|
168
|
+
network: Network.Testnet,
|
|
169
|
+
phrase: phrase,
|
|
170
|
+
feeBounds: { lower: 1, upper: 5 },
|
|
171
|
+
}
|
|
172
|
+
const client = new Client(params, 'Ed25519')
|
|
173
|
+
const fees: Fees = await radixClient.getFees()
|
|
174
|
+
console.log(fees)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Getting transactions history
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
import { Network, XChainClientParams } from '@xchainjs/xchain-client/lib'
|
|
181
|
+
import { Client } from '@xchainjs/xchain-radix'
|
|
182
|
+
|
|
183
|
+
const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
|
|
184
|
+
const params: XChainClientParams = {
|
|
185
|
+
network: Network.Testnet,
|
|
186
|
+
phrase: phrase,
|
|
187
|
+
feeBounds: { lower: 1, upper: 5 },
|
|
188
|
+
}
|
|
189
|
+
const client = new Client(params, 'Ed25519')
|
|
190
|
+
|
|
191
|
+
const transactionsHistoryParams = {
|
|
192
|
+
address: 'account_rdx169yt0y36etavnnxp4du5ekn7qq8thuls750q6frq5xw8gfq52dhxhg',
|
|
193
|
+
offset: 72533720,
|
|
194
|
+
limit: 200,
|
|
195
|
+
asset: 'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd',
|
|
196
|
+
}
|
|
197
|
+
const txs = await (await radixClient.getTransactions(transactionsHistoryParams)).txs
|
|
198
|
+
console.log(txs)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Service providers
|
|
202
|
+
|
|
203
|
+
This package uses the following service providers
|
|
204
|
+
|
|
205
|
+
| Function | Service | Notes | Rate limits |
|
|
206
|
+
| --------------------------- | --------------------- | --------------------------------------------------------------------------------- | ------------------------ |
|
|
207
|
+
| Balances | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/StateEntityDetails | 1550 requests per minute |
|
|
208
|
+
| Transaction history | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/StreamTransactions | 1550 requests per minute |
|
|
209
|
+
| Transaction details by hash | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionCommittedDetails | 1550 requests per minute |
|
|
210
|
+
| Fees | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionPreview | 1550 requests per minute |
|
|
211
|
+
| Transaction broadcast | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionSubmit | 1550 requests per minute |
|
|
212
|
+
| Transfer | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionSubmit | 1550 requests per minute |
|
|
213
|
+
| Explorer | Dashboard | https://dashboard.radixdlt.com/ | |
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { GatewayApiClient, TransactionSubmitResponse } from '@radixdlt/babylon-gateway-api-sdk';
|
|
3
|
+
import { Curve, Intent, NotarizedTransaction, PrivateKey, PublicKey, TransactionHash } from '@radixdlt/radix-engine-toolkit';
|
|
4
|
+
import { AssetInfo, Balance, BaseXChainClient, Fees, Network, PreparedTx, Tx, TxHistoryParams, TxParams, TxsPage, XChainClientParams } from '@xchainjs/xchain-client';
|
|
5
|
+
import { Address, Asset } from '@xchainjs/xchain-util';
|
|
6
|
+
/**
|
|
7
|
+
* The main client for the Radix network which is then wrapped by the {Client} adapting it to have
|
|
8
|
+
* a {BaseXChainClient} interface.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RadixSpecificClient {
|
|
11
|
+
private innerNetwork;
|
|
12
|
+
private innerGatewayClient;
|
|
13
|
+
constructor(networkId: number);
|
|
14
|
+
set networkId(networkId: number);
|
|
15
|
+
get networkId(): number;
|
|
16
|
+
get gatewayClient(): GatewayApiClient;
|
|
17
|
+
currentEpoch(): Promise<number>;
|
|
18
|
+
currentStateVersion(): Promise<number>;
|
|
19
|
+
fetchBalances(address: string): Promise<Balance[]>;
|
|
20
|
+
fetchNFTBalances(address: string): Promise<Balance[]>;
|
|
21
|
+
private convertResourcesToBalances;
|
|
22
|
+
private fetchNonFungibleResources;
|
|
23
|
+
private fetchFungibleResources;
|
|
24
|
+
constructSimpleTransferIntent(from: string, to: string, resourceAddress: string, amount: number, notaryPublicKey: PublicKey, message?: string): Promise<{
|
|
25
|
+
intent: Intent;
|
|
26
|
+
fees: number;
|
|
27
|
+
}>;
|
|
28
|
+
submitTransaction(notarizedTransaction: NotarizedTransaction): Promise<[TransactionSubmitResponse, TransactionHash]>;
|
|
29
|
+
private static createGatewayClient;
|
|
30
|
+
private static simpleTransferManifest;
|
|
31
|
+
private constructIntent;
|
|
32
|
+
private previewIntent;
|
|
33
|
+
private static retPublicKeyToGatewayPublicKey;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Custom Radix client
|
|
37
|
+
*/
|
|
38
|
+
export default class Client extends BaseXChainClient {
|
|
39
|
+
private radixSpecificClient;
|
|
40
|
+
private curve;
|
|
41
|
+
constructor({ network, phrase, rootDerivationPaths, feeBounds, curve, }: XChainClientParams & {
|
|
42
|
+
curve?: Curve;
|
|
43
|
+
});
|
|
44
|
+
get radixClient(): RadixSpecificClient;
|
|
45
|
+
setNetwork(network: Network): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get an estimated fee for a test transaction that involves sending
|
|
48
|
+
* XRD from one account to another
|
|
49
|
+
*
|
|
50
|
+
* @returns {Fee} An estimated fee
|
|
51
|
+
*/
|
|
52
|
+
getFees(): Promise<Fees>;
|
|
53
|
+
getRadixNetwork(): number;
|
|
54
|
+
getPrivateKey(index: number): Buffer;
|
|
55
|
+
getRadixPrivateKey(index: number): PrivateKey;
|
|
56
|
+
/**
|
|
57
|
+
* Get the address for a given account.
|
|
58
|
+
* @deprecated Use getAddressAsync instead.
|
|
59
|
+
*/
|
|
60
|
+
getAddress(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current address asynchronously for a given account.
|
|
63
|
+
* @returns {Address} A promise resolving to the current address.
|
|
64
|
+
* A phrase is needed to create a wallet and to derive an address from it.
|
|
65
|
+
*/
|
|
66
|
+
getAddressAsync(index?: number): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Get the explorer URL based on the network.
|
|
69
|
+
*
|
|
70
|
+
* @returns {string} The explorer URL based on the network.
|
|
71
|
+
*/
|
|
72
|
+
getExplorerUrl(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Get the explorer URL for a given account address based on the network.
|
|
75
|
+
* @param {Address} address The address to generate the explorer URL for.
|
|
76
|
+
* @returns {string} The explorer URL for the given address.
|
|
77
|
+
*/
|
|
78
|
+
getExplorerAddressUrl(address: Address): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the explorer URL for a given transaction ID based on the network.
|
|
81
|
+
* @param {string} txID The transaction ID to generate the explorer URL for.
|
|
82
|
+
* @returns {string} The explorer URL for the given transaction ID.
|
|
83
|
+
*/
|
|
84
|
+
getExplorerTxUrl(txID: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Validate the given address.
|
|
87
|
+
* @param {Address} address The address to validate.
|
|
88
|
+
* @returns {boolean} `true` if the address is valid, `false` otherwise.
|
|
89
|
+
*/
|
|
90
|
+
validateAddressAsync(address: string): Promise<boolean>;
|
|
91
|
+
validateAddress(address: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves the balances of a given address.
|
|
94
|
+
* @param {Address} address - The address to retrieve the balance for.
|
|
95
|
+
* @param {Asset[]} assets - Assets to retrieve the balance for (optional).
|
|
96
|
+
* @returns {Promise<Balance[]>} An array containing the balance of the address.
|
|
97
|
+
*/
|
|
98
|
+
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Get transaction history of a given address with pagination options.
|
|
101
|
+
* @param {TxHistoryParams} params The options to get transaction history. (optional)
|
|
102
|
+
* @returns {TxsPage} The transaction history.
|
|
103
|
+
*/
|
|
104
|
+
getTransactions(params: TxHistoryParams): Promise<TxsPage>;
|
|
105
|
+
/**
|
|
106
|
+
* Get the transaction details of a given transaction id.
|
|
107
|
+
* This method uses LTSRadixEngineToolkit.Transaction.summarizeTransaction
|
|
108
|
+
* to convert a transaction hex to a transaction summary. If the transaction was not built with
|
|
109
|
+
* the SimpleTransactionBuilder, the method will fail to get the transaction data
|
|
110
|
+
* @param {string} txId The transaction id.
|
|
111
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
112
|
+
*/
|
|
113
|
+
getTransactionData(txId: string): Promise<Tx>;
|
|
114
|
+
/**
|
|
115
|
+
* Helper function to convert a transaction in hex, returned by the gateway to a Tx type
|
|
116
|
+
* @param transaction_hex - The raw_hex returned by the gateway for a transaction id
|
|
117
|
+
* @param confirmed_at - The confirmed_at date for the transaction
|
|
118
|
+
* @param intent_hash - The transaction intent hash
|
|
119
|
+
* @returns a transaction in Tx type
|
|
120
|
+
*/
|
|
121
|
+
convertTransactionFromHex(transaction_hex: string, intent_hash: string, confirmed_at: Date): Promise<Tx>;
|
|
122
|
+
/**
|
|
123
|
+
* Creates a transaction using the SimpleTransactionBuilder, signs it with the
|
|
124
|
+
* private key and returns the signed hex
|
|
125
|
+
* @param params - The transactions params
|
|
126
|
+
* @returns A signed transaction hex
|
|
127
|
+
*/
|
|
128
|
+
transfer(params: TxParams): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Submits a transaction
|
|
131
|
+
* @param txHex - The transaction hex build with the transfer method
|
|
132
|
+
* @returns - The response from the gateway
|
|
133
|
+
*/
|
|
134
|
+
broadcastTx(txHex: string): Promise<string>;
|
|
135
|
+
/**
|
|
136
|
+
* Prepares a transaction to be used by the transfer method
|
|
137
|
+
* It will include a non signed transaction
|
|
138
|
+
* @param params - The transaction params
|
|
139
|
+
* @returns a PreparedTx
|
|
140
|
+
*/
|
|
141
|
+
prepareTx(params: TxParams): Promise<PreparedTx>;
|
|
142
|
+
/**
|
|
143
|
+
* Get asset information.
|
|
144
|
+
* @returns Asset information.
|
|
145
|
+
*/
|
|
146
|
+
getAssetInfo(): AssetInfo;
|
|
147
|
+
}
|
|
148
|
+
export { Client };
|
package/lib/const.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RootDerivationPaths } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Asset } from '@xchainjs/xchain-util';
|
|
3
|
+
/**
|
|
4
|
+
* Chain identifier for Radix.
|
|
5
|
+
* This constant represents the identifier for the Radix Chain.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RadixChain: "RADIX";
|
|
8
|
+
export declare const MAINNET_GATEWAY_URL = "https://mainnet.radixdlt.com";
|
|
9
|
+
export declare const STOKENET_GATEWAY_URL = "https://stokenet.radixdlt.com";
|
|
10
|
+
export declare const XRD_DECIMAL = 18;
|
|
11
|
+
export declare const XrdAssetMainnet: Asset;
|
|
12
|
+
export declare const XrdAssetStokenet: Asset;
|
|
13
|
+
export declare const xrdRootDerivationPaths: RootDerivationPaths;
|
|
14
|
+
export declare const bech32Networks: {
|
|
15
|
+
[key: number]: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const bech32Lengths: {
|
|
18
|
+
[key: number]: number;
|
|
19
|
+
};
|
|
20
|
+
interface FeesEstimationParams {
|
|
21
|
+
from: string;
|
|
22
|
+
to: string;
|
|
23
|
+
resourceAddress: string;
|
|
24
|
+
publicKey: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const feesEstimationPublicKeys: {
|
|
27
|
+
[networkId: number]: FeesEstimationParams;
|
|
28
|
+
};
|
|
29
|
+
export declare const assets: {
|
|
30
|
+
[networkId: number]: Asset;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
package/lib/index.d.ts
ADDED