-
Notifications
You must be signed in to change notification settings - Fork 129
Create Bitcoin Anchor
-
The blockchain nodes much start
defidwith-spvenabled. If test on testnet, also need to enable-spv_testnetoption. If test on regtest, then need to enable-fakespv. -
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.
Using this method need to setup the BRChainParams parameters in the source code first, then compile the source code and run it as a DeFi Chain node.
typedef struct {
const char * const *dnsSeeds; // NULL terminated array of dns seeds
uint16_t standardPort;
uint32_t magicNumber;
uint64_t services;
int (*verifyDifficulty)(const BRMerkleBlock *block, const BRSet *blockSet); // blockSet must have last 2016 blocks
const BRCheckPoint *checkpoints;
size_t checkpointsCount;
// prefixes
uint8_t privkey, base58_p2pkh, base58_p2sh;
char const * const bip32_xprv;
char const * const bip32_xpub;
char const * const bech32;
} BRChainParams;
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
We have an automation tool to create anchor.
git clone https://github.com/DeFiCh/defi-btc-anchorer.git
Follow the readme to setup the parameter in config.toml then use the tool to create anchor, there is no need to change the DeFi Chain source code.
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 -testnet spv_listanchors
Results:
[
{
"btcBlockHeight": 1896976,
"btcTxHash": "7af242e42795303cb51eb62300e4c8e776d65c3ad2a6191e74af4d2e59debb33",
"defiBlockHeight": 116790,
"defiBlockHash": "4c3f370d801a119b427eaaaffb0a24819c26497dd23d08a99e2153e2e571a44a",
"rewardAddress": "74pBZ3tYbRvCuuagy65R9DjbmZpxMbnFaq",
"confirmations": 56,
"active": true
},
{
"btcBlockHeight": 1896971,
"btcTxHash": "56ff5d4dc8155b608d1f8f30c7f892ef80b99652efa4ce5880b41f12bbae4c08",
"defiBlockHeight": 116730,
"defiBlockHash": "c4f509d43747d0196b2aef2d3b80aeff79518f6346b89b8b4c1f52e0e5fe7909",
"rewardAddress": "74pBZ3tYbRvCuuagy65R9DjbmZpxMbnFaq",
"confirmations": 61,
"active": true
}
]