constructor

Creates an instance of the Computer class.

Type

new (config: {
  chain?: 'LTC' | 'BTC' | 'DOGE',
  network?: 'mainnet' | 'testnet' | 'regtest',
  mnemonic?: string,
  path?: string,
  passphrase?: string
  addressType?: 'p2pkh' | 'p2wpkh' | 'p2tr',
  url?: string,
  satPerByte?: number,
  moduleStorageType?: 'taproot' | 'multisig'
}) => Computer

Parameters

config

A configuration object with the properties listed below. All properties are optional.

Key Description Default
chain Target blockchain LTC
network Target network regtest
mnemonic BIP39 mnemonic phrase Random phrase
path BIP32 path m/44'/1'/0'
passphrase BIP32 passphrase ''
addressType Address type p2pkh
url Url of a Bitcoin Computer Node https://rltc.node.bitcoincomputer.io
satPerByte Fee in satoshi per byte 2
moduleStorageType Store JavaScript modules on Taproot (taproot) or bare multisig (multisig). Taproot (default where available) produces no hygiene dust outputs for the module encoding txs and supports larger modules (with SegWit discount) but uses a two-tx pattern. Multisig uses single-tx direct data storage (with hygiene dust outputs). Choose based on minimization goals and high-throughput single-tx UX needs. See Fees "User Choices..." section. taproot

Return Value

An instance of the Computer class

Examples

import { Computer } from '@bitcoin-computer/lib'
import { chain, expect, network, url } from '../../utils/index.js'

describe('constructor', () => {
  // Default configuration
  it('Should connects to a remote node by default', () => {
    const computer = new Computer()
    expect(computer.getChain()).eq('LTC')
    expect(computer.getNetwork()).eq('regtest')
    expect(computer.getUrl()).eq('https://rltc.node.bitcoincomputer.io')
  })

  // Local configuration
  it('Should connect to a local node', async () => {
    const computer = new Computer({ chain, network, url })
    expect(computer.getChain()).eq('LTC')
    expect(computer.getNetwork()).eq('regtest')
    expect(computer.getUrl()).eq('http://127.0.0.1:1031')
  })

  // Custom configuration
  it('Should connect to custom parameters', async () => {
    const computer = new Computer({
      chain: 'BTC',
      network: 'mainnet',
      url: 'your-node-url',
      path: "m/44'/0'/0'/0",
      passphrase: 'hi',
      mode: 'prod',
    })
    expect(computer.getChain()).eq('BTC')
    expect(computer.getNetwork()).eq('mainnet')
    expect(computer.getUrl()).eq('your-node-url')
    expect(computer.getPath()).eq("m/44'/0'/0'/0")
    expect(computer.getPassphrase()).eq('hi')
  })
})

Source