Skip to content

Instantly share code, notes, and snippets.

Last active Oct 19, 2020
What would you like to do?
  1. Let's generate an address!
$ blockstack-cli generate-sk --testnet > testnet_key.json
  1. Set some envars
$ secret_key=$(cat ./testnet_key.json | jq -r .secretKey)
$ stx_addr=$(cat ./testnet_key.json | jq -r .stacksAddress)
  1. Now we need some STX, let's ask the faucet
$ curl -X POST\?address\=$stx_addr
  1. Once we have the STX, we should create a stack-stx transaction to participate. First, we need to raw hex bytes of the address we'll use to receive STX. I use the c32check npm package to do this:
$ node -e "const c32 = require('c32check'); console.log('0x' + c32.c32addressDecode('$stx_addr')[1])"
  1. Now we build and sign our transaction
$ blockstack-cli contract-call --testnet $secret_key \
                 243 0 \
                 ST000000000000000000002AMW42H pox stack-stx \
                 -e "(* u33 (pow u10 u14))" \
                 -e '{ hashbytes: 0x5e230097e7d9568810b336b8c8ed6bed21ac2f96, version: 0x00 }' \
                 -e "u3" \
                 -e "u400" > /tmp/transaction.hex

The first few arguments specify your STX testnet key, the fee to pay for the transaction, and the nonce of the transaction. Then, we specify the PoX smart contract and function to call. Then there are four arguments to the Clarity function:

  1. The total number of microSTX to stack: here we use 3.3e15
  2. The PoX rewards address to receive awards. This is the hex bytes we generated before.
  3. The number of reward cycles to lock up for.
  4. The burn block height at which this Stacking transaction should be considered valid. This burn block height
      should be close to the current chain tip -- you can find the current `burn_block_height` by querying
  1. Broadcast the transaction
cat /tmp/transaction.hex | xxd -r -p | curl -v -X POST --header "Content-Type:application/octet-stream" --data-binary @-
Copy link

diwakergupta commented Sep 24, 2020

This is great, thanks Aaron!

Copy link

agraebe commented Sep 24, 2020


Copy link

agraebe commented Sep 24, 2020

@kantai - Does this use the stacks-2.0-tx (PR) version of the CLI?

Copy link

kantai commented Sep 24, 2020

This uses the binary blockstack-cli produced by the stacks-blockchain repo's cargo build.

Copy link

agraebe commented Sep 24, 2020

I just tried this and failed at the faucet step (assuming reasoned by the fixes we're currently working on). I also noticed that the faucet URL needs to be updated:\?address\=$stx_addr

Copy link

jcnelson commented Sep 25, 2020

This is great @kantai! Just a small nit: 1. The total number of STX to stack: here we use 3.3e15 <-- the units here are uSTX.

Question: would it be possible to extend the runbook to show how a user will know whether or not they've received their BTC reward from Stacking?

Copy link

agraebe commented Oct 5, 2020

@kantai - the faucet call requires the stacking=true URL param now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment