How to use @ledgerhq/ledger-core - 10 common examples

To help you get started, we’ve selected a few @ledgerhq/ledger-core 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 LedgerHQ / ledger-live-desktop / alix.js View on Github external
console.log(`> Creating transport`)
    const transport = await CommNodeHid.open(device.path)

    // transport.setDebugMode(true)

    console.log(`> Instanciate BTC app`)
    const hwApp = new Btc(transport)

    console.log(`> Get currency`)
    const currency = await getCurrency('bitcoin_testnet')

    console.log(`> Create wallet`)
    const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')

    console.log(`> Create account`)
    const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)

    console.log(`> Sync account`)
    if (CREATE) {
      await syncAccount(account)
    }

    console.log(`> Create transaction`)
    const transaction = await createTransaction(wallet, account)
    const signedTransaction = await signTransaction(hwApp, transaction)

    await account.asBitcoinLikeAccount().broadcastRawTransaction(signedTransaction)
    // console.log(signedTransaction);

    process.exit(0)
    // console.log(account.getIndex());
    // console.log(account.isSynchronizing());
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
console.log(`> Instanciate BTC app`)
    const hwApp = new Btc(transport)

    console.log(`> Get currency`)
    const currency = await getCurrency('bitcoin_testnet')

    console.log(`> Create wallet`)
    const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')

    console.log(`> Create account`)
    const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)

    console.log(`> Sync account`)
    if (CREATE) {
      await syncAccount(account)
    }

    console.log(`> Create transaction`)
    const transaction = await createTransaction(wallet, account)
    const signedTransaction = await signTransaction(hwApp, transaction)

    await account.asBitcoinLikeAccount().broadcastRawTransaction(signedTransaction)
    // console.log(signedTransaction);

    process.exit(0)
    // console.log(account.getIndex());
    // console.log(account.isSynchronizing());
  } catch (err) {
    console.log(err.message)
    process.exit(1)
  }
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
const currency = await getCurrency('bitcoin_testnet')

    console.log(`> Create wallet`)
    const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')

    console.log(`> Create account`)
    const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)

    console.log(`> Sync account`)
    if (CREATE) {
      await syncAccount(account)
    }

    console.log(`> Create transaction`)
    const transaction = await createTransaction(wallet, account)
    const signedTransaction = await signTransaction(hwApp, transaction)

    await account.asBitcoinLikeAccount().broadcastRawTransaction(signedTransaction)
    // console.log(signedTransaction);

    process.exit(0)
    // console.log(account.getIndex());
    // console.log(account.isSynchronizing());
  } catch (err) {
    console.log(err.message)
    process.exit(1)
  }
})
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
async function createTransaction(wallet, account) {
  const ADDRESS_TO_SEND = 'n2jdejywRogCunR2ozZAfXp1jMnfGpGXGR'

  const bitcoinLikeAccount = account.asBitcoinLikeAccount()
  const walletCurrency = wallet.getCurrency()
  const amount = createAmount(walletCurrency, 10000)

  console.log(`--------------------------------`)
  console.log(amount.toLong())
  console.log(`-----------------after `)
  const fees = createAmount(walletCurrency, 1000)

  const transactionBuilder = bitcoinLikeAccount.buildTransaction()
  transactionBuilder.sendToAddress(amount, ADDRESS_TO_SEND)
  // TODO: don't use hardcoded value for sequence (and first also maybe)
  transactionBuilder.pickInputs(0, 0xffffff)
  transactionBuilder.setFeesPerByte(fees)

  return transactionBuilder.build()
}
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
async function createTransaction(wallet, account) {
  const ADDRESS_TO_SEND = 'n2jdejywRogCunR2ozZAfXp1jMnfGpGXGR'

  const bitcoinLikeAccount = account.asBitcoinLikeAccount()
  const walletCurrency = wallet.getCurrency()
  const amount = createAmount(walletCurrency, 10000)

  console.log(`--------------------------------`)
  console.log(amount.toLong())
  console.log(`-----------------after `)
  const fees = createAmount(walletCurrency, 1000)

  const transactionBuilder = bitcoinLikeAccount.buildTransaction()
  transactionBuilder.sendToAddress(amount, ADDRESS_TO_SEND)
  // TODO: don't use hardcoded value for sequence (and first also maybe)
  transactionBuilder.pickInputs(0, 0xffffff)
  transactionBuilder.setFeesPerByte(fees)

  return transactionBuilder.build()
}
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
// })
  // console.log(accounts)
  try {
    console.log(`> Creating transport`)
    const transport = await CommNodeHid.open(device.path)

    // transport.setDebugMode(true)

    console.log(`> Instanciate BTC app`)
    const hwApp = new Btc(transport)

    console.log(`> Get currency`)
    const currency = await getCurrency('bitcoin_testnet')

    console.log(`> Create wallet`)
    const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')

    console.log(`> Create account`)
    const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)

    console.log(`> Sync account`)
    if (CREATE) {
      await syncAccount(account)
    }

    console.log(`> Create transaction`)
    const transaction = await createTransaction(wallet, account)
    const signedTransaction = await signTransaction(hwApp, transaction)

    await account.asBitcoinLikeAccount().broadcastRawTransaction(signedTransaction)
    // console.log(signedTransaction);
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
// const accounts = await scanAccountsOnDevice({
  //   devicePath: device.path,
  //   currencyId: 'bitcoin_testnet',
  // })
  // console.log(accounts)
  try {
    console.log(`> Creating transport`)
    const transport = await CommNodeHid.open(device.path)

    // transport.setDebugMode(true)

    console.log(`> Instanciate BTC app`)
    const hwApp = new Btc(transport)

    console.log(`> Get currency`)
    const currency = await getCurrency('bitcoin_testnet')

    console.log(`> Create wallet`)
    const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')

    console.log(`> Create account`)
    const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)

    console.log(`> Sync account`)
    if (CREATE) {
      await syncAccount(account)
    }

    console.log(`> Create transaction`)
    const transaction = await createTransaction(wallet, account)
    const signedTransaction = await signTransaction(hwApp, transaction)
github LedgerHQ / ledger-live-desktop / src / init-ledger-core.js View on Github external
module.exports = () => {
  if (!instanciated) {
    core.instanciateWalletPool({
      // sqlite files will be located in the app local data folder
      dbPath: process.env.LEDGER_LIVE_SQLITE_PATH,
    })
    instanciated = true
  }
  return core
}
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
async function scanNextAccount(wallet, hwApp, accountIndex = 0) {
  console.log(`creating an account with index ${accountIndex}`)
  const account = await createAccount(wallet, hwApp)
  console.log(`synchronizing account ${accountIndex}`)
  await syncAccount(account)
  console.log(`finished sync`)
  const utxoCount = await account.asBitcoinLikeAccount().getUTXOCount()
  console.log(`utxoCount = ${utxoCount}`)
}
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
async function scanNextAccount(wallet, hwApp, accountIndex = 0) {
  console.log(`creating an account with index ${accountIndex}`)
  const account = await createAccount(wallet, hwApp)
  console.log(`synchronizing account ${accountIndex}`)
  await syncAccount(account)
  console.log(`finished sync`)
  const utxoCount = await account.asBitcoinLikeAccount().getUTXOCount()
  console.log(`utxoCount = ${utxoCount}`)
}