Skip to content

Create Bitcoin Anchor

Xiao Shengguang edited this page Dec 12, 2020 · 7 revisions

Create Bitcoin Anchor

Prerequisites

  1. The blockchain nodes much start defid with -spv enabled. If test on testnet, also need to enable -spv_testnet option. If test on regtest, then need to enable -fakespv.

  2. If create anchor on bitcoin mainnet, then need to run a bitcoin node. If create anchor on bitcoin testnet, then need to run a bitcoin testnet node.

Create Anchor

The anchor is created with API command spv_createanchor. The first and second parameters are compulsary. An example on regtest

./defi-cli -regtest -rpcport=19554 spv_createanchor "[{\"txid\":\"528e61b53dcf04448693247866198ed0cf6488c42eb4f493f25da251f0a3af59\",\"vout\":3,\"amount\":10000,\"privkey\":\"your_private_key\"}]" mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy true 5000

Example on testnet:

./src/defi-cli -testnet spv_createanchor "[{\"txid\":\"528e61b53dcf04448693247866198ed0cf6488c42eb4f493f25da251f0a3af59\",\"vout\":3,\"amount\":106870,\"privkey\":\"your_private_key\"}]" 7AJwxLqAcN1zbkA8m33c5wFy8EGkzRghVX true 5000

Check Create Anchor Result

"confirmations": 0,

Using API spv_listanchors to get the list of anchors, from the result can find out the status of the anchor. If the confirmations larger than 0 and active is true means the anchor creation is succeful. For example

./defi-cli -regtest -rpcport=19554 spv_listanchors

Results:

[
  {
    "btcBlockHeight": 2147483647,
    "btcTxHash": "fe1ed5886a9d8c28e37207e5a9445b46ae194737d50ce4c0e3173b79c96dc02c",
    "defiBlockHeight": 825,
    "defiBlockHash": "a1ffdd28e6e7234028cd7d895b1733148b8e1157f553e16941ada8944edc68db",
    "rewardAddress": "mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy",
    "confirmations": 0,
    "active": false
  },
  {
    "btcBlockHeight": 0,
    "btcTxHash": "8b6417d4bfbb4c5ac2a2c3535520bb56b82183456fc94e17f5f5fe1a037ab5eb",
    "defiBlockHeight": 855,
    "defiBlockHash": "e272df159d2a305d86df8b3c2b9b3a8414ad7290151a035bf5e642979918f472",
    "rewardAddress": "mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy",
    "confirmations": 1,
    "active": true
  }
]