How to use the blockstack.config.network function in blockstack

To help you get started, we’ve selected a few blockstack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blockstack / stacks-wallet / app / common / lib / transactions.js View on Github external
recipientAddress,
  amount,
  walletType,
  memo = ""
) => {
  // generate our btc addresses for sender and recipient
  const senderBtcAddress = c32ToB58(senderAddress);
  const recipientBtcAddress = c32ToB58(recipientAddress);

  // define token type (always stacks)
  const tokenType = "STACKS";

  const tokenAmount = toBigInt(amount); // convert to bigi

  // get an estimate
  const utxos = await config.network.getUTXOs(senderBtcAddress);
  const numUTXOs = utxos.length;

  const estimate =
    (await transactions.estimateTokenTransfer(
      recipientBtcAddress,
      tokenType,
      tokenAmount,
      memo,
      numUTXOs
    )) + 5500;

  // current BTC balance
  const btcBalance = sumUTXOs(utxos);

  // account status
  const accountStatus = await config.network.getAccountStatus(
github blockstack / stacks-wallet / app / common / lib / transactions.js View on Github external
tokenType,
      tokenAmount,
      memo,
      numUTXOs
    )) + 5500;

  // current BTC balance
  const btcBalance = sumUTXOs(utxos);

  // account status
  const accountStatus = await config.network.getAccountStatus(
    senderBtcAddress,
    tokenType
  );
  // current STACKS balance
  const currentAccountBalance = await config.network.getAccountBalance(
    senderBtcAddress,
    tokenType
  );

  // current Block Height
  const blockHeight = await config.network.getBlockHeight();

  // check for our errors

  // not enough btc
  if (btcBalance < estimate) {
    return {
      ...ERRORS.INSUFFICIENT_BTC_BALANCE,
      estimate,
      btcBalance,
      difference: estimate - btcBalance
github blockstack / stacks-wallet / blockstack-ledger / utils.js View on Github external
export function getMultiSigInfo(publicKeys, signersRequired) {
  const redeem = btc.payments.p2ms({ m: signersRequired, pubkeys: publicKeys })
  const script = btc.payments.p2sh({ redeem })
  const address = script.address
  return {
    address: bskConfig.network.coerceAddress(address),
    redeemScript: redeem.output.toString('hex')
  }
}
github blockstack / stacks-wallet / blockstack-ledger / LedgerSigner.js View on Github external
.then(result => {
          this.address = bskConfig.network.coerceAddress(result.bitcoinAddress)
          return this.address
        })
        .catch(err => {
github blockstack / stacks-wallet / app / containers / SettingsPage.js View on Github external
renderView(view) {
    switch(view) {
      case VIEWS.DEFAULT:
        return ;
      default:
        return <div></div>;
    }
  }
github blockstack / blockstack-browser / app / js / account / store / account / actions.js View on Github external
return dispatch => {
    logger.info('Broadcasting bitcoin transaction')
    logger.debug('Transaction hex:', txHex)
    dispatch(broadcastTransaction())

    if (regTestMode) {
      logger.info('Using regtest network to broadcast transaction')
      config.network = network.defaults.LOCAL_REGTEST
      config.network.blockstackAPIUrl = 'http://localhost:6270'
    }

    return config.network
      .broadcastTransaction(txHex)
      .then(res => {
        logger.info(`Broadcasting bitcoin transaction succesful: ${res}`)
        dispatch(broadcastTransactionSuccess())
      })
      .catch(err => {
        logger.error(`Failed to broadcast bitcoin transaction: ${err}`)
        dispatch(broadcastTransactionError(err.message || err.toString()))
      })
  }
}
github blockstack / stacks-wallet / blockstack-ledger / utils.js View on Github external
function getTransactionBitcoind (txId) {
  const bitcoindUrl = bskConfig.network.btc.bitcoindUrl
  const bitcoindCredentials = bskConfig.network.btc.bitcoindCredentials

  const jsonRPC = {
    jsonrpc: '1.0',
    method: 'getrawtransaction',
    params: [txId]
  }

  const authString = Buffer.from(`${bitcoindCredentials.username}:${bitcoindCredentials.password}`)
      .toString('base64')
  const headers = { Authorization: `Basic ${authString}` }
  return fetch(bitcoindUrl, {
    method: 'POST',
    body: JSON.stringify(jsonRPC),
    headers
  })
github blockstack / stacks-wallet / app / containers / SettingsPage.js View on Github external
renderView(view) {
    switch(view) {
      case VIEWS.DEFAULT:
        return ;
      default:
        return <div></div>;
    }
  }
github blockstack / stacks-wallet / blockstack-trezor / TrezorSigner.js View on Github external
.map( output => {
        if (btc.script.toASM(output.script).startsWith('OP_RETURN')) {
          const nullData = btc.script.decompile(output.script)[1]
          return { 'op_return_data': nullData.toString('hex'),
                   amount: '0',
                   'script_type': 'PAYTOOPRETURN' }
        } else {
          const address = bskConfig.network.coerceAddress(
            btc.address.fromOutputScript(output.script))
          return { address,
                   amount: `${output.value}`,
                   'script_type': 'PAYTOADDRESS' }
        }
      })
  }
github blockstack / stacks-wallet / app / vendor / blockstack-trezor / TrezorSigner.js View on Github external
return TrezorSigner.getPublicKeys([hdpath]).then(pks => {
      const address = btc.payments.p2pkh({ pubkey: Buffer.from(pks[0], "hex") })
        .address;
      return bskConfig.network.coerceAddress(address);
    });
  }