Skip to content

Anchor API Document

Shengguang Xiao edited this page Nov 20, 2020 · 2 revisions

Anchor API Document

spv_createanchor

( [{"txid":"hex","vout":n,"amount":n,"privkey":"str"},...] ) "rewardAddress" ( send feerate )

Creates (and optional submits to bitcoin blockchain) an anchor tx with latest possible (every 15th) authorized blockhash. The first argument is the specific UTXOs to spend.

Arguments:
1. inputs                     (json array, optional) A json array of json objects
     [
       {                      (json object)
         "txid": "hex",       (string, required) The transaction id
         "vout": n,           (numeric, required) The output number
         "amount": n,         (numeric, required) Amount of output in satoshis
         "privkey": "str",    (string, required) WIF private key for signing this output
       },
       ...
     ]
2. rewardAddress              (string, required) User's P2PKH address (in DeFi chain) for reward
3. send                       (boolean) Send it to btc network (Default = true)
4. feerate                    (numeric) Feerate (satoshis) per 1000 bytes (Default = 1000)

Result:
"txHex"                  (string) The hex-encoded raw transaction with signature(s)
"txHash"                 (string) The hex-encoded transaction hash

Examples:
> defi-cli spv_createanchor "[{\"txid\":\"id\",\"vout\":0,\"amount\":10000,\"privkey\":\"WIFprivkey\"}]" \"rewardAddress\" True 2000
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_createanchor", "params": ["[{\"txid\":\"id\",\"vout\":0,\"amount\":10000,\"privkey\":\"WIFprivkey\"}]" \"rewardAddress\" True 2000] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_createanchortemplate

"rewardAddress"

Creates an anchor tx template with latest possible (every 15th) authorized blockhash.

Arguments:
1. rewardAddress    (string, required) User's P2PKH address (in DeFi chain) for reward

Result:
"txHex"                  (string) The hex-encoded raw transaction with signature(s)

Examples:
> defi-cli spv_createanchortemplate "[{\"txid\":\"id\",\"vout\":0,\"amount\":10000,\"privkey\":\"WIFprivkey\"}]" \"rewardAddress\"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_createanchortemplate", "params": ["[{\"txid\":\"id\",\"vout\":0,\"amount\":10000,\"privkey\":\"WIFprivkey\"}]" \"rewardAddress\"] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_estimateanchorcost

( feerate )

Estimates current anchor cost with default fee, one input and one change output.

Arguments:
1. feerate    (numeric) Feerate (satoshis) per 1000 bytes (Default = 1000)

Result:
"cost"                  (numeric) Estimated anchor cost (satoshis)

Examples:
> defi-cli spv_estimateanchorcost
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_estimateanchorcost", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_gettxconfirmations

"txhash"

Reports tx confirmations (if any)...

Arguments:
1. txhash    (string, required) Hash of tx to look for

Result:
count                (num) Tx confirmations. Zero if not confirmed yet (mempooled?) and -1 if not found

Examples:
> defi-cli spv_gettxconfirmations \"txid\"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_gettxconfirmations", "params": [\"txid\"] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_listanchorauths

List anchor auths (if any)

Result:
"array"                  Returns array of anchor auths

Examples:
> defi-cli spv_listanchorauths
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_listanchorauths", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_listanchorrewardconfirms

List anchor reward confirms (if any)

Result:
"array"                  Returns array of anchor confirms

Examples:
> defi-cli spv_listanchorrewardconfirms
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_listanchorrewardconfirms", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_listanchorrewards

List anchor rewards (if any)

Result:
"array"                  Returns array of anchor rewards

Examples:
> defi-cli spv_listanchorrewards
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_listanchorrewards", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_listanchors

( minBtcHeight maxBtcHeight minConfs maxConfs )

List anchors (if any)

Arguments:
1. minBtcHeight    (numeric) min btc height, optional (default = -1)
2. maxBtcHeight    (numeric) max btc height, optional (default = -1)
3. minConfs        (numeric) min anchor confirmations, optional (default = -1)
4. maxConfs        (numeric) max anchor confirmations, optional (default = -1)

Result:
"array"                  Returns array of anchors

Examples:
> defi-cli spv_listanchors 1500000 -1 6 -1
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_listanchors", "params": [-1 -1 0 0] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_rescan

( height )

Rescan from block height...

Arguments:
1. height    (numeric) Block height or ('tip' minus 'height') if negative).

Result:
"none"                  Returns nothing

Examples:
> defi-cli spv_rescan 600000
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_rescan", "params": [600000] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_sendrawtx

"rawtx"

Sending raw tx to DeFi Blockchain

Arguments:
1. rawtx    (string, required) The hex-encoded raw transaction with signature

Result:
"none"                  Returns nothing

Examples:
> defi-cli spv_sendrawtx "rawtx"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_sendrawtx", "params": ["rawtx"] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

spv_syncstatus

Returns spv sync status

Result:
{                           (json object)
   "connected"                (bool) Connection status
   "current"                  (num) Last synced block
   "estimated"                (num) Estimated chain height (as reported by peers)
}

Examples:
> defi-cli spv_syncstatus
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "spv_syncstatus", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/