Coding Guide
A coding overview to XChainJS.
Last updated
Was this helpful?
A coding overview to XChainJS.
Last updated
Was this helpful?
The foundation of xchainjs is defined in the package
Address
: a crypto address as a string.
BaseAmount
: a bigNumber in 1e8 format. E.g. 1 BTC = 100,000,000 in BaseAmount
AssetAmount
: a BaseAmount*10^8. E.g. 1 BTC = 1 in Asset Amount.
Asset
: Asset details {Chain, symbol, ticker, isSynth}
CryptoAmount:
is a class that has:
All crypto should use the CryptoAmount
object with the understanding they are in BaseAmount format. An example to switch between them:
Major data types for the mayarchain-query package.
The input Type for estimateSwap
. This is designed to be created by interfaces and passed into EstimateSwap. Also see Swap Memo for more information.
Variable
Data Type
Comments
input
CryptoAmount
inbound asset and amount
destinationAsset
Asset
outbound asset
destinationAddress
String
outbound asset address
slipLimit
BigNumber
Optional: Used to set LIM
affiliateFeePercent
number
Optional: 0-0.1 allowed
affiliateAddress
Address
Optional: thor address
interfaceID
string
Optional: assigned interface ID
The internal return type is used within estimateSwap after the calculation is done.
Variable
Data Type
Comments
totalFees
TotalFees
All fees for swap
slipPercentage
BigNumber
Actual slip of the swap
netOutput
CryptoAmount
input - totalFees
waitTimeSeconds
number
Estimated time for the swap
canSwap
boolean
false if there is an issue
errors
string array
contains info if canSwap is false
Return type of estimateSwap
. This is designed to be used by interfaces to give them all the information they need to display to the user.
Variable
Data Type
Comments
txEstimate
SwapEstimate
swap details
memo
string
constructed memo MAYAChain will understand
expiry
DateTime
when the SwapEstimate information will no longer be valid.
toAddress
string
current Asgard Vault address From inbound_address
Do not use toAddress
after expiry
as the Asgard vault rotates
Major data types for the thorchain-query package.
Package description
Code examples
Install procedures
Input Type for doSwap where a swap will be actually conducted. Based on EstimateSwapParams.
Variable
Text
Text
hash
string
inbound Tx Hash
url
string
Block exploer url
waitTimeSeconds
number
Estimated time for the swap