1.1.8 • Published 6 months ago

@xchainjs/xchain-radix v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@xchainjs/xchain-radix

Radix module for XChainJS clients

Modules

Installation

yarn add @xchainjs/xchain-radix

Create a new account

import { generateMnemonic } from 'bip39'

const mnemonic = generateMnemonic()
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: mnemonic,
}
const client = new Client(params)
const address = await client.getAddressAsync()

Fund an account in testnet

yarn fund account_address

Examples

Creating a radix client

import { Network, XChainClientParams } from '@xchainjs/xchain-client'
import { Client } from '@xchainjs/xchain-radix'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: phrase,
  feeBounds: { lower: 1, upper: 5 },
}
const client = new Client(params, 'Ed25519')
console.log(client.getAssetInfo())

Creating a transaction

There are two methods related to creating transactions: prepareTx and transfer The first one creates a raw unsigned transaction (it doesn't submit the transaction). The second one submits the transaction to the ledger

prepareTx

import { Network, TxParams, XChainClientParams } from '@xchainjs/xchain-client'
import { Client, XrdAssetStokenet } from '@xchainjs/xchain-radix'
import { baseAmount } from '@xchainjs/xchain-util/lib'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: phrase,
  feeBounds: { lower: 1, upper: 5 },
}

async function main() {
  const client = new Client(params, 'Ed25519')

  const txParams: TxParams = {
    asset: XrdAssetStokenet,
    amount: baseAmount(1),
    recipient: 'account_tdx_2_129wjagjzxltd0clr3q4z7hqpw5cc7weh9trs4e9k3zfwqpj636e5zf',
    memo: 'test',
  }
  const preparedTx = await client.prepareTx(txParams)
  console.log(preparedTx)
}

main().catch(console.error)

transfer

import { Network, TxParams, XChainClientParams } from '@xchainjs/xchain-client'
import { Client, XrdAssetStokenet } from '@xchainjs/xchain-radix'
import { baseAmount } from '@xchainjs/xchain-util/lib'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: phrase,
  feeBounds: { lower: 1, upper: 5 },
}

async function main() {
  const client = new Client(params, 'Ed25519')

  const txParams: TxParams = {
    asset: XrdAssetStokenet,
    amount: baseAmount(1),
    recipient: 'account_tdx_2_129wjagjzxltd0clr3q4z7hqpw5cc7weh9trs4e9k3zfwqpj636e5zf',
    memo: 'test',
  }
  const transactionId = await client.transfer(txParams)
  console.log(transactionId)
}

main().catch(console.error)

Getting a transaction data

import { Network, Tx, TxParams, XChainClientParams } from '@xchainjs/xchain-client/lib'
import { Client } from '@xchainjs/xchain-radix'
import { XrdAsset } from '@xchainjs/xchain-radix/src/const'
import { baseAmount } from '@xchainjs/xchain-util'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Mainnet,
  phrase: phrase,
}
const client = new Client(params, 'Ed25519')

const txParams: TxParams = {
  asset: XrdAsset,
  amount: baseAmount(1000),
  recipient: 'account_rdx169yt0y36etavnnxp4du5ekn7qq8thuls750q6frq5xw8gfq52dhxhg',
}
const transferTransaction = await radixClient.transfer(txParams)
const transaction: Tx = await radixClient.getTransactionData(transferTransaction)
console.log(transaction)

Getting balances

import { Balance, Network, XChainClientParams } from '@xchainjs/xchain-client/lib'
import { Client } from '@xchainjs/xchain-radix'
import { Asset } from '@xchainjs/xchain-util/lib'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: phrase,
  feeBounds: { lower: 1, upper: 5 },
}
const assets: Asset[] = [
  {
    symbol: 'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd',
    ticker: 'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd',
    chain: 'radix',
    synth: false,
  },
]
const balances: Balance[] = await radixClient.getBalance(
  'account_rdx16x47guzq44lmplg0ykfn2eltwt5wweylpuupstsxnfm8lgva7tdg2w',
  assets,
)
console.log(balances)

Getting fees

import { Fees, Network, XChainClientParams } from '@xchainjs/xchain-client/lib'
import { Client } from '@xchainjs/xchain-radix'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: phrase,
  feeBounds: { lower: 1, upper: 5 },
}
const client = new Client(params, 'Ed25519')
const fees: Fees = await radixClient.getFees()
console.log(fees)

Getting transactions history

import { Network, XChainClientParams } from '@xchainjs/xchain-client/lib'
import { Client } from '@xchainjs/xchain-radix'

const phrase = 'rural bright ball negative already grass good grant nation screen model pizza'
const params: XChainClientParams = {
  network: Network.Testnet,
  phrase: phrase,
  feeBounds: { lower: 1, upper: 5 },
}
const client = new Client(params, 'Ed25519')

const transactionsHistoryParams = {
  address: 'account_rdx169yt0y36etavnnxp4du5ekn7qq8thuls750q6frq5xw8gfq52dhxhg',
  offset: 72533720,
  limit: 200,
  asset: 'resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd',
}
const txs = await (await radixClient.getTransactions(transactionsHistoryParams)).txs
console.log(txs)

Service providers

This package uses the following service providers

FunctionServiceNotesRate limits
BalancesRadix Network Gatewayhttps://radix-babylon-gateway-api.redoc.ly/#operation/StateEntityDetails1550 requests per minute
Transaction historyRadix Network Gatewayhttps://radix-babylon-gateway-api.redoc.ly/#operation/StreamTransactions1550 requests per minute
Transaction details by hashRadix Network Gatewayhttps://radix-babylon-gateway-api.redoc.ly/#operation/TransactionCommittedDetails1550 requests per minute
FeesRadix Network Gatewayhttps://radix-babylon-gateway-api.redoc.ly/#operation/TransactionPreview1550 requests per minute
Transaction broadcastRadix Network Gatewayhttps://radix-babylon-gateway-api.redoc.ly/#operation/TransactionSubmit1550 requests per minute
TransferRadix Network Gatewayhttps://radix-babylon-gateway-api.redoc.ly/#operation/TransactionSubmit1550 requests per minute
ExplorerDashboardhttps://dashboard.radixdlt.com/
1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

7 months ago

1.1.5

9 months ago

1.1.4

10 months ago

1.1.1

10 months ago

1.0.2

11 months ago

1.1.0

10 months ago

1.1.3

10 months ago

1.0.4

10 months ago

1.1.2

10 months ago

1.0.3

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.1.1

1 year ago