diff --git a/src/pages/stacks-blockchain/accounts.md b/src/pages/stacks-blockchain/accounts.md index acd6bfcd..8118ee0b 100644 --- a/src/pages/stacks-blockchain/accounts.md +++ b/src/pages/stacks-blockchain/accounts.md @@ -110,6 +110,8 @@ npx -q stacks-gen sk --testnet } ``` +-> The stacking object with hashbytes and a version represents the bitcoin address derived from the Stacks address. Read more about the [bitcoin address format](/stacks-blockchain/stacking#bitcoin-address). + Full documentation available at [stacks-gen](https://github.com/psq/stacks-gen). ## Querying diff --git a/src/pages/stacks-blockchain/integrate-stacking.md b/src/pages/stacks-blockchain/integrate-stacking.md index 3f0d34dd..f1112489 100644 --- a/src/pages/stacks-blockchain/integrate-stacking.md +++ b/src/pages/stacks-blockchain/integrate-stacking.md @@ -234,7 +234,7 @@ unlockingAt.setSeconds( At this point, your app shows Stacking details. If Stacking is executed and the user has enough funds, the user should be asked to provide input for the amount of microstacks to lockup and a bitcoin address to be used to pay out rewards. --> The sample code used assumes usage of the bitcoin address associated with the Stacks account. You can replace this with an address provided by the users or read from your database +-> The sample code used assumes usage of the bitcoin address associated with the Stacks account. You can replace this with an address provided by the users or read from your database. Read more about the [bitcoin address format](/stacks-blockchain/stacking#bitcoin-address). With this input, and the data from previous steps, we can determine the eligibility for the next reward cycle: diff --git a/src/pages/stacks-blockchain/stacking.md b/src/pages/stacks-blockchain/stacking.md index 37ecab79..c4fd4c53 100644 --- a/src/pages/stacks-blockchain/stacking.md +++ b/src/pages/stacks-blockchain/stacking.md @@ -77,3 +77,34 @@ Stacking is a built-in capability of PoX and is realized through a set of action ## Stacking contract Check out the [Stacking contract reference](/references/stacking-contract) to see available methods and error codes. + +## Bitcoin address + +The Stacking contract needs a special format for the bitcoin address (the reward address). This is required in order to ensure that miners will be able to correctly construct the bitcoin transaction containing the reward address. + +!> An invalid reward address could cause miners to be unable to mine a block + +The address must be specified in the following format using the Clarity language: + +```clar +;; a tuple of a version and hashbytes buffer +(pox-addr (tuple (version (buff 1)) (hashbytes (buff 20)))) +``` + +The `version` buffer must represent what kind of bitcoin address is being submitted. It can be one of the following: + +```js +SerializeP2PKH = 0x00, // hash160(public-key), same as bitcoin's p2pkh +SerializeP2SH = 0x01, // hash160(multisig-redeem-script), same as bitcoin's multisig p2sh +SerializeP2WPKH = 0x02, // hash160(segwit-program-00(p2pkh)), same as bitcoin's p2sh-p2wpkh +SerializeP2WSH = 0x03, // hash160(segwit-program-00(public-keys)), same as bitcoin's p2sh-p2wsh +``` + +The `hashbytes` are the 20 hash bytes of the bitcoin address. You can obtain that from a bitcoin library, for instance using [`bitcoinjs-lib`](https://github.com/bitcoinjs/bitcoinjs-lib): + +```js +const btc = require('bitcoinjs-lib'); +console.log( + '0x' + btc.address.fromBase58Check('1C56LYirKa3PFXFsvhSESgDy2acEHVAEt6').hash.toString('hex') +); +```