Skip to main content

Spv API

import {JsonRpcClient} from '@defichain/jellyfish-api-jsonrpc'
const client = new JsonRpcClient('http://foo:bar@localhost:8554')

// Using client.spv.
const something = await client.spv.method()

getNewAddress

Creates and adds a Bitcoin address to the SPV wallet.

client.spv.getNewAddress()
interface spv {
getNewAddress (): Promise<string>
}

getAddressPubKey

Returns a Bitcoin address's public key.

client.spv.getAddressPubKey()
interface spv {
getAddressPubKey (address: string): Promise<string>
}

listReceivedByAddress

List balances by receiving address.

client.spv.listReceivedByAddress()
interface spv {
listReceivedByAddress (minConfirmation: number = 1, address?: string): Promise<ReceivedByAddressInfo[]>
}

interface ReceivedByAddressInfo {
address: string
type: string
amount: BigNumber
confirmations: number
txids: string[]
}

sendToAddress

Send a Bitcoin amount to a given address.

client.spv.sendToAddress()
interface spv {
sendToAddress (address: string, amount: BigNumber, options: SpvDefaultOptions = { feeRate: new BigNumber('10000') }): Promise<SendMessageResult>
}

interface SpvDefaultOptions {
feeRate?: BigNumber
}

interface SendMessageResult {
txid: string
sendmessage: string
}

createHtlc

Creates a Bitcoin address whose funds can be unlocked with a seed or as a refund.

client.spv.createHtlc()
interface spv {
createHtlc (receiverPubKey: string, ownerPubKey: string, options: CreateHtlcOptions): Promise<CreateHtlcResult>
}

interface CreateHtlcOptions {
timeout: string
seedhash?: string
}

interface CreateHtlcResult {
address: string
redeemScript: string
seed?: number
seedhash?: string
}

decodeHtlcScript

Decode and return value in a HTLC redeemscript.

client.spv.decodeHtlcScript()
interface spv {
decodeHtlcScript (redeemScript: string): Promise<DecodeHtlcResult>
}

interface DecodeHtlcResult {
sellerkey: string
buyerkey: string
blocks: number
hash: string
}

claimHtlc

Claims all coins in HTLC address.

client.spv.claimHtlc()
interface spv {
claimHtlc (scriptAddress: string, destinationAddress: string, options: ClaimHtlcOptions): Promise<SendMessageResult>
}

interface ClaimHtlcOptions {
seed: string
feeRate?: BigNumber
}

interface SendMessageResult {
txid: string
sendmessage: string
}

getHtlcSeed

Returns the HTLC secret if available.

client.spv.getHtlcSeed()
interface spv {
getHtlcSeed (address: string): Promise<string>
}

refundHtlc

Refunds all coins in HTLC address.

client.spv.refundHtlc()
interface spv {
refundHtlc (scriptAddress: string, destinationAddress: string, options: SpvDefaultOptions = { feeRate: new BigNumber('10000') }): Promise<SendMessageResult>
}

interface SpvDefaultOptions {
feeRate?: BigNumber
}

interface SendMessageResult {
txid: string
sendmessage: string
}

refundHtlcAll

Gets all HTLC contracts stored in wallet and creates refunds transactions for all that have expired

client.spv.refundHtlcAll()
interface spv {
refundHtlcAll (destinationAddress: string, options: SpvDefaultOptions = { feeRate: new BigNumber('10000') }): Promise<string[]>
}

interface SpvDefaultOptions {
feeRate?: BigNumber
}

listHtlcOutputs

List all outputs related to HTLC addresses in the wallet.

client.spv.listHtlcOutputs()
interface spv {
listHtlcOutputs (scriptAddress?: string): Promise<ListHtlcsOutputsResult[]>
}

interface SpentInfo {
txid: string
confirms: number
}

interface ListHtlcsOutputsResult {
txid: string
vout: number
amount: BigNumber
address: string
confirms: number
spent: SpentInfo
}

listAnchorRewardConfirms

List anchor reward confirms.

client.spv.listAnchorRewardConfirms()"
interface spv {
listAnchorRewardConfirms (): Promise<ListAnchorRewardConfirmsResult[]>
}

export interface ListAnchorRewardConfirmsResult {
btcTxHeight: number
btcTxHash: string
anchorHeight: number
dfiBlockHash: string
prevAnchorHeight: number
rewardAddress: string
confirmSignHash: string
signers: number
}

listAnchorsUnrewarded

List unrewarded anchors.

client.spv.listAnchorsUnrewarded()"
interface spv {
listAnchorsUnrewarded (): Promise<ListAnchorsResult[]>
}

interface ListAnchorsResult {
btcBlockHeight: number
btcBlockHash: string
btcTxHash: string
previousAnchor: string
defiBlockHeight: number
defiBlockHash: string
rewardAddress: string
confirmations: number
signatures: number
active?: boolean
anchorCreationHeight?: number
}

listAnchorRewards

List anchor rewards.

client.spv.listAnchorRewards()"
interface spv {
listAnchorRewards (): Promise<ListAnchorRewardsResult[]>
}

interface ListAnchorRewardsResult {
AnchorTxHash: string
RewardTxHash: string
}

createAnchor

Create, sign and send anchor tx, using only SPV API.

client.spv.createAnchor()"
interface spv {
createAnchor (
createAnchorInputs: CreateAnchorInput[], rewardAddress: string, options: CreateAnchorOptions = { send: true, feerate: 1000 }
): Promise<CreateAnchorResult>
}

interface CreateAnchorInput {
txid: string
vout: number
amount: number
privkey: string
}

interface CreateAnchorOptions {
send?: boolean
feerate?: number
}

interface CreateAnchorResult {
txHex: string
txHash: string
defiHash: string
defiHeight: number
estimatedReward: BigNumber
cost: BigNumber
sendResult: number
sendMessage: string
}

listAnchors

List anchors.

client.spv.listAnchors()"
interface spv {
listAnchors (
options: ListAnchorsOptions = { minBtcHeight: -1, maxBtcHeight: -1, minConfs: -1, maxConfs: -1, startBTCHeight: -1, limit: -1 }
): Promise<ListAnchorsResult[]>
}

interface ListAnchorsOptions {
minBtcHeight?: number
maxBtcHeight?: number
minConfs?: number
maxConfs?: number
startBTCHeight?: number
limit?: number
}

interface ListAnchorsResult {
btcBlockHeight: number
btcBlockHash: string
btcTxHash: string
previousAnchor: string
defiBlockHeight: number
defiBlockHash: string
rewardAddress: string
confirmations: number
signatures: number
active?: boolean
anchorCreationHeight?: number
}

listAnchorsPending

List pending anchors in mempool.

client.spv.listAnchorsPending()"
interface spv {
listAnchorsPending (): Promise<ListAnchorsResult[]>
}

interface ListAnchorsResult {
btcBlockHeight: number
btcBlockHash: string
btcTxHash: string
previousAnchor: string
defiBlockHeight: number
defiBlockHash: string
rewardAddress: string
confirmations: number
signatures: number
active?: boolean
anchorCreationHeight?: number
}

listAnchorAuths

List anchor auths.

client.spv.listAnchorAuths()"
interface spv {
listAnchorAuths (): Promise<ListAnchorAuthsResult[]>
}

interface ListAnchorAuthsResult {
previousAnchor: string
blockHeight: number
blockHash: string
creationHeight: number
signers: number
signees?: string[]
}

setLastHeight

Set last height on BTC chain, use for testing purpose.

client.spv.setLastHeight()"
interface spv {
setLastHeight (height: number): Promise<void>
}