Stacks

Stacks

Stacks can be accessed with the following coin types:

EnvironmentCoin TypeFaucet
STX Productionstx
STX Testnettstxhttps://docs.stacks.co/understand-stacks/testnet#faucet

Explorer

https://explorer.hiro.so/

Generating wallets

1 2 3 4 5 6 7 8 9 10 11 bitgo .coin('tstx') .wallets() .generateWallet({ label: 'My Test Wallet', passphrase: 'secretpassphrase1a5df8380e0e30', }) .then(function (wallet) { // print the new wallet console.dir(wallet); });
1 2 3 4 5 6 7 8 LABEL="My Test Wallet" PASSPHRASE="secretpassphrase1a5df8380e0e30" curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -d "{ \"label\": \"$LABEL\", \"passphrase\": \"$PASSPHRASE\" }" \ http://$BITGO_EXPRESS_HOST:3080/api/v2/tbtc4/wallet/generate

Creating addresses

1 2 3 4 5 6 7 8 9 10 11 bitgo .coin('tstx') .wallets() .getWallet({ id: '585c51a5df8380e0e3082e46' }) .then(function (wallet) { return wallet.createAddress(); }) .then(function (newAddress) { // print new address details console.dir(newAddress); });
1 2 3 4 5 WALLET=585c51a5df8380e0e3082e46 curl -X POST \ -H "Authorization: Bearer $ACCESS_TOKEN" \ https://app.bitgo-test.com/api/v2/tstx/wallet/$WALLET/address

Balances

Stacks (STX) is the native asset of the Stacks blockchain. It is called a "token," but as a layer-1 asset it is treated here as a coin. The base unit of STX is a micro-STX:

  • 1 micro-STX is (10-6) or 0.000001 STX.
  • 1 STX is (106) or 1000000 micro-STX (1 million).

Balances are supported in string format: balanceString, confirmedBalanceString, and spendableBalanceString.

Fee rate

Fees are calculated based on the estimate fee rate and the size of the raw transaction in bytes. The fee rate is a market determined variable. For the testnet, it is set to 1 micro-STX.

Set the fee manually

In order to set the fee manually, add feeRate param to the body of the request.

Example for single recipient transfer:

1 2 3 4 5 6 7 { recipients: [{ amount: amount, //string - amount in micro-stx address: receiverAddress, //string }], feeRate: 500000 // amount in micro-stx as number or string, equal to 0.5 STX }

Send-Many: send to multiple recipients

Stacks doesn't provide a native functionality to send to many recipients in the same transaction but there is smart contract that allows us to do it. It also supports for memos on each receiver. In order to use it, the recipients params in the body of a transfer transaction should have more than 1 recipient object.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { recipients: [{ amount: "amount1", //string - amount in micro-stx address: "receiverAddress1", //string memo: "memo1", //string - optional },{ amount: "amount2", //string - amount in micro-stx address: "receiverAddress2", //string memo: "memo2", //string - optional },{ amount: "amount3", //string - amount in micro-stx address: "receiverAddress3", //string memo: "memo3", //string - optional },{ amount: "amount4", //string - amount in micro-stx address: "receiverAddress4", //string memo: "memo4", //string - optional }], }

Staking

Stacks refers to staking as stacking. Stacks is a proof of stake protocol where users can delegate part of their funds to a validator (or "stacker") to stake and get rewards for participating in securing the network. Stacks has a unique staking mechanism where users delegate STX but earn BTC as reward. When users delegate, funds are “locked” but remain in the wallet. Users must undelegate to “unlock” the funds to be withdrawn or sent out.

Currently, BitGo allows users to act as delegators which means that from their wallets they can:

  • Delegate (or stake) STX
  • Undelegate (or unstake) STX
  • Receive rewards for delegating STX.

Delegating

Staking cycles run in sequence. Users must delegate their funds before the cycle ends in order to generate rewards from a stacker (validator).

Note: BitGo recommends that users use a specific BTC address solely for generating rewards.

Stacks staking examples

These examples are for wallet endpoints like:

https://app.bitgo.com/api/v2/stx/wallet/walletId/tx/build
https://app.bitgo.com/api/v2/stx/wallet/walletId/tx/initiate

Delegate

To get the BTC Address hash and version BitGo recommends that you use a script like this:

Note: Addresses must be in legacy format (and start with a 1 or a 3). Native SegWit addresses (that start with bc1) are not supported.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 const bitcoinjs = require('bitcoinjs-lib'); const btcAddress = '1QF7K4izEcgDxu9yRBLpFe6viFihiL1w5j'; const parsedAddress = bitcoinjs.address.fromBase58Check(btcAddress); const btcAddressVersionToHashMode = (version) => { switch (version) { case '0': // BTC version for mainnet P2PKH case '111': // BTC version for testnet P2PKH return { data: [0], type: 'Buffer' }; case '5': // BTC version for mainnet P2SH case '196': // BTC version for testnet P2SH return { data: [1], type: 'Buffer' }; default: break; } }; const AddressHash = bas58.hash.toJSON(); const AddressVersion = btcAddressVersionToHashMode(parsedAddress.version.toString()); console.log(AddressHash); //{type: 'Buffer',data: [ 254, 245, 252, 42, 179, 220, 238, 122, 241, 132, 202, 47, 217, 13, 20, 38, 151, 116, 250, 128]} console.log(AddressVersion); //{ data: [ 0 ], type: 'Buffer' }

The body of the request transaction should look like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 { type: "stakingLock", recipients: [{ amount: amount, //string - amount in micro-stx address: validatorAddress, //string }], stakingOptions: { contractName: 'pox', functionName: 'delegate-stx', functionArgs: [ // First param is the amount in micro-stx do delegate { type: 'uint128', val: amount //string - amount in micro-stx }, // Second param is validator address { type: 'principal', val: validatorAddress //string }, // Third param is the delegation cycles that delegate permisions will last. // Is a required parameter and must be a 1 or higher. { type: 'optional', val: numberOfCycles //string }, // Fourth param is the BTC address in which you will receive the rewards. // Is required. { type: 'optional', val: { type: 'tuple', val: [{ key: 'hashbytes', type: 'buffer', val: AddressHash }, { key: 'version', type: 'buffer', val: AddressVersion }, ], }, }, ], }; }

Revoke delegate

The body of the request transaction should look like this:

1 2 3 4 5 6 7 8 9 10 11 12 { type: "stakingUnlock", recipients: [{ amount: '0', // string address: '', // empty string }], stakingOptions: { contractName: 'pox', functionName: 'revoke-delegate-stx', functionArgs: [] // empty array }, }