Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xchainjs/xchain-client

Package Overview
Dependencies
Maintainers
2
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-client

## Get Client Returns the client. ``` getClient(): XChainClient ```

  • 0.0.5
  • npm
  • Socket score

Version published
Weekly downloads
96
decreased by-65.09%
Maintainers
2
Weekly downloads
 
Created
Source

XChain Wallet Client Interface

Get Client

Returns the client.

getClient(): XChainClient

Set Network

Used to set a type of NETWORK, which is either MAINNET or TESTNET.

enum Network {
  TEST = 'testnet',
  MAIN = 'mainnet',
}
setNetwork(net: Network): XChainClient

Returns the client.

Get Network

Returns the current network, to set conditional responses for other functions (like which network to send transactions to, etc). Normally used internally, but can be used externally.

getNetwork(): Network

Returns the network.

Get Explorer URL

Returns the correctly formatted url string for either paths for:

  • Addresses
  • Transactions

The default Explorer baseURL can be hard-coded.

enum Path {
  address = 'address',
  tx = 'tx',
}
getExplorerUrl(type: Path, param: string): string

The function should return the correctly formatted url string.

Set NODE URL

Sets the url to the remote node attached to the client, for getting on-chain data and broadcasting transactions. The default Node URL can be hard-coded, making this function optional.

setNodeURL(url: string)

Set NODE API

Sets an API key if the client needs an API key to access its remote node. If no key is set, either the node has no API key or the client is expected to stay within node rate limits.

setNodeAPIKey(key: string)

Set Phrase

Wallet calls to set the master BIP39 phrase.

setPhrase(phrase: string): address

The function should return the address generated by the phrase.

Get Balance

Returns the balance of an address. If address not passed, gets the balance of the current address.

  • Queries the NodeURL for the balance
  • Returns an array of coins and balances, with assets in chain notation CHAIN.SYMBOL-ID
  • Converts to 8 decimal places for conformity
getBalance(address?: Address): Promise<Balances>

Example of a third-party service query https://api.blockchair.com/bitcoin/addresses/balances?addresses=34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo

Example of a coin array:

[
  { 
    "coin" : "BTC.BTC"
    "amount" : 100000000
   }
]

Get Transactions

Gets a simplied array of recent transactions for an address.

getTransactions(params?: GetTxsParams): Promise<TxPage>

Example of third party service to help: https://api.blockchair.com/bitcoin/outputs?recipient=34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo

Example of return:

[
  { 
    "from" : "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo"
    "to" : 34vRoCGJym3xR7yCVPFHoCNxv4Twseoxp4
    "amount: 100000000,
    "date" : date-time-group
   }
]

Due to the complexity of this function and dependence of third-party services, this function can be omitted in early versions of the client.

Transfer

General transfer function. The transaction should be signed and broadcast using the Node URL. The fee should always be rate, which is units per transaction size. The size should be calculated on the fly or hardcoded:

  • Bitcoin: 250 bytes is typical, so feeRate of 10 is 10 sats per byte, eg, 2500 sats
  • Ethereum: gwei is standard, so a feeRate of 20 would be interpreted as 20 GWEI
  • Binance Chain: fixed size, so the feeRate is ignored.
export type TxParams = {
  asset: string // BTC.BTC
  amount: number // in base format (10**8)
  recipient: address // address
  feeRate: number // feeRate 
  memo: string // optional memo to pass
}

transfer(params: TxParams): Promise<TransferResult>

The function should return the hash of the finalised transaction.

Deposit

Specific vault transaction to deposit assets into THORChain. If the deposit function is the same as the transfer function, it should wrap it. If it is separate (smart contract call) that logic should be done here.

deposit(params: TxParams): Promise<TransferResult>

The function should return the hash of the finalised transaction.

Get Fees

This function calculates and returns the fee object.

getFees(): Promise<Fees>

This should return an object of fee rates for a simple transfer function.

  • Fast (target of next block)
  • Average (target of 2 blocks)
  • Slow (target of 3 blocks)

Example, the following are sats/byte rates for Bitcoin. If this was ethereum, they would be GWEI.

[{"fast" : 100
"average" : 50
"slow" : 20}]

Edge cases

  • If the chain is final, still return the array, but all values will be the same.
  • If the chain has dynamic fees, logic should be called here to get the latest chain fees, ie from the Node.

FAQs

Package last updated on 20 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc