npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xchainjs/xchain-radix

v1.1.3

Published

Custom Radix client and utilities used by XChainJS clients

Downloads

669

Readme

@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

| Function | Service | Notes | Rate limits | | --------------------------- | --------------------- | --------------------------------------------------------------------------------- | ------------------------ | | Balances | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/StateEntityDetails | 1550 requests per minute | | Transaction history | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/StreamTransactions | 1550 requests per minute | | Transaction details by hash | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionCommittedDetails | 1550 requests per minute | | Fees | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionPreview | 1550 requests per minute | | Transaction broadcast | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionSubmit | 1550 requests per minute | | Transfer | Radix Network Gateway | https://radix-babylon-gateway-api.redoc.ly/#operation/TransactionSubmit | 1550 requests per minute | | Explorer | Dashboard | https://dashboard.radixdlt.com/ | |