/fuego-api

Fuego (XFG) JavaScript RPC API

Primary LanguageJavaScriptMIT LicenseMIT

Fuego-API: Javascript/Node.js interface (RPC/API)

Javascript/Node.js interface to Fuego cryptocurrency RPC/API.

There are three RPC servers built in to the three programs fuegod, Fuegowallet and walletd. They can each be started with the argument --help to display command line options.

Fuegod

A node on the P2P network (daemon) with no wallet functions; console interactive. To launch:

$ ./fuegod

The default daemon RPC port is 18180 and the default P2P port is 10808.

walletd

A node on the P2P network (daemon) with wallet functions; console non-interactive. To launch, assuming that your my.wallet file is in the current directory:

$ ./walletd --container-file my.wallet --container-password PASSWD --local --bind-port 18181

The wallet functions RPC port is 18181. The default daemon P2P port is 10808. The default daemon RPC port is 18180. The --local option activates the daemon; otherwise, a remote daemon can be used.

Fuegowallet

A simple wallet; console interactive unless RPC server is running; requires access to a node daemon for full functionality. To launch, assuming that your my.wallet file is in the current directory:

$ ./Fuegowallet --rpc-bind-port 8070 --wallet-file my --password PASSWORD

The wallet functions RPC port is 8070. By default the wallet connects with the daemon on port 18180. It is possible to run several instances simultaneously using different wallets and ports.

Quick start for node.js

$ npm install Fuego-api
$ ./fuegod # launch the network daemon
$ ./Fuegowallet --rpc-bind-port PORT --wallet-file my --password PASSWORD # launch the simple wallet

Create and run a test program.

$ node test.js

The test program could contain, for example, a payment via the simple wallet's RPC server

const XFG = require('fuego-api')
const ccx = new XFG({
  daemonHost: 'http://localhost', 
  walletHost: 'http://localhost', 
  daemonRpcPort: 18180,
  walletRpcPort: 8070
})

fuego.send([{
  address: 'fireCd9BNW6UYQnFbTZ8XFKr8Xfcxc9HJUMu7J6HJxnwDvjvjPUko2yXSeAZQCUbV7CxdR7rJKX63HDhDjzWxWCNA5iYhbHSjz',
  amount: 1234567
}])
.then((res) => { console.log(res) }) // display tx hash upon success
.catch((err) => { console.log(err) }) // display error message upon failure

API

const XFG = require('Fuego-api')
const xfg = new XFG({
  daemonHost: <daemonHost>, 
  walletHost: <walletHost>,
  daemonRpcPort: <daemonRpcPort>,
  walletRpcPort: <walletRpcPort>,
  timeout: <timeout>
})

xfg.rpc returns a promise, where rpc is any of the methods below:

Wallet RPC (must provide walletRpcPort)

Get height (Fuegowallet)

xfg.height() // get last block height
xfg.balance() // get wallet balances
const opts = {
  firstTxId: FIRST_TX_ID, // (integer, optional), ex: 10
  txLimit: TX_LIMIT // maximum number of messages (integer, optional), ex: 10
}
xfg.messages(opts) // opts can be omitted
const paymentId = PAYMENT_ID // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.payments(paymentId)
xfg.transfers() // gets all transfers
xfg.outputs() // gets outputs available as inputs for a new transaction
xfg.reset() // discard wallet cache and resync with block chain
xfg.store() // save wallet cache to disk
xfg.optimize() // combines many available outputs into a few by sending to self
const transfers = [{ address: ADDRESS, amount: AMOUNT, message: MESSAGE }, ...] // ADDRESS = destination address (string, required), AMOUNT = raw XFG (integer, required), MESSAGE = transfer message to be encrypted (string, optional)
const opts = {
  transfers: transfers, // (array, required), ex: [{ address: 'fireCd9...', amount: 1000, message: 'refund' }]
  fee: FEE, // (raw XFG integer, optional, default is minimum required), ex: 10
  anonimity: MIX_IN, // input mix count (integer, optional, default 2), ex: 6
  paymentId: PAYMENT_ID, // (64-digit hex string, optional), ex: '0ab1...3f4b'
  unlockHeight: UNLOCK_HEIGHT // block height to unlock payment (integer, optional), ex: 12750
}
xfg.send(opts)
const viewSecretKey = VIEW_SECRET_KEY // (64-digit hex string, optional), ex: '0ab1...3f4b'
xfg.resetOrReplace(viewSecretKey) // If no key, wallet is re-synced. If key, a new address is created from the key for a new wallet.
xfg.status()
const address = ADDRESS // (string, required), ex: 'fireCd9...'
xfg.getBalance(address)
xfg.createAddress()
const address = ADDRESS // (string, required), ex: 'fireCd9...'
xfg.deleteAddress(address)
xfg.getAddresses()
xfg.getViewSecretKey()
const address = ADDRESS // (string, required), ex: 'fireCd9...'
xfg.getSpendKeys(address)
const firstBlockIndex = FIRST_BLOCK_INDEX // index of first block (integer, required), ex: 12750
const blockCount = BLOCK_COUNT // number of blocks to include (integer, required), ex: 30
xfg.getBlockHashes(firstBlockIndex, blockCount)
const hash = HASH // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.getTransaction(hash) // get transaction details given hash
const addresses = [ADDRESS1, ADDRESS2, ...] // ADDRESS = address string; address to include
xfg.getUnconfirmedTransactions(addresses) // addresses can be omitted
const opts = { // either blockHash or firstBlockIndex is required
  blockHash: BLOCK_HASH, // hash of first block (64-digit hex string, see comment above), ex: '0ab1...3f4b'
  firstBlockIndex: FIRST_BLOCK_INDEX, // index of first block (integer, see comment above), ex: 12750
  blockCount: BLOCK_COUNT, // number of blocks to include (integer, required), ex: 30
  addresses: [ADDRESS, ...], filter (array of address strings, optional), ex: ['fireCd9...']
  paymentId: PAYMENT_ID // filter (64-digit hex string, optional), ex: '0ab1...3f4b'
}
xfg.getTransactionHashes(opts)
const opts = { // either blockHash or firstBlockIndex is required
  blockHash: BLOCK_HASH, // hash of first block (64-digit hex string, see comment above), ex: '0ab1...3f4b'
  firstBlockIndex: FIRST_BLOCK_INDEX, // index of first block (integer, see comment above), ex: 12750
  blockCount: BLOCK_COUNT, // number of blocks to include (integer, required), ex: 30
  addresses: [ADDRESS, ...], filter (array of address strings, optional), ex: ['fireCd9...']
  paymentId: PAYMENT_ID // filter (64-digit hex string, optional), ex: '0ab1...3f4b'
}
xfg.getTransactions(opts)
const transfers = [{ address: ADDRESS, amount: AMOUNT, message: MESSAGE }, ...] // ADDRESS = destination address (string, required), AMOUNT = raw XFG (integer, required), MESSAGE = transfer message to be encrypted (string, optional)
const addresses = [ADDRESS1, ADDRESS2, ...] // ADDRESS = source address string; address in wallet to take funds from
const opts = {
  transfers: transfers, // (array, required), ex: [{ address: 'fireCd9...', amount: 1000, message: 'tip' }]
  addresses: addresses, // (array, optional), ex: ['fireCd9...', 'xfg7Xe...']
  changeAddress: ADDRESS, // change return address (address string, optional if only one address in wallet or only one source address given), ex: 'fireCd9...'
  paymentId: PAYMENT_ID, // filter (64-digit hex string, optional), ex: '0ab1...3f4b'
  anonimity: MIX_IN, // input mix count (integer, optional, default 2), ex: 6
  fee: FEE, // (raw XFG integer, optional, default is minimum required), ex: 10
  unlockHeight: UNLOCK_HEIGHT, // block height to unlock payment (integer, optional), ex: 12750
  extra: EXTRA // (variable length string, optional), ex: '123abc'
}
xfg.sendTransaction(opts)
const transfers = [{ address: ADDRESS, amount: AMOUNT, message: MESSAGE }, ...] // ADDRESS = destination address (string, required), AMOUNT = raw XFG (integer, required), MESSAGE = transfer message to be encrypted (string, optional)
const addresses = [ADDRESS1, ADDRESS2, ...] // ADDRESS = source address string; address in wallet to take funds from
const opts = {
  transfers: transfers, // (array, required), ex: [{ address: 'fireCd9...', amount: 1000, message: 'tip' }]
  addresses: addresses, // (array, optional), ex: ['fireCd9...', 'xfg7Xe...']
  changeAddress: ADDRESS, // change return address (address string, optional if only one address in wallet or only one source address given), ex: 'fireCd9...'
  paymentId: PAYMENT_ID, // filter (64-digit hex string, optional), ex: '0ab1...3f4b'
  anonimity: MIX_IN, // input mix count (integer, optional, default 2), ex: 6
  fee: FEE, // (raw XFG integer, optional, default is minimum required), ex: 10
  unlockHeight: UNLOCK_HEIGHT, // block height to unlock payment (integer, optional), ex: 12750
  extra: EXTRA // (variable length string, optional), ex: '123abc'
}
xfg.createDelayedTransaction(opts) // create but do not send transaction
xfg.getDelayedTransactionHashes()
const hash = HASH // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.deleteDelayedTransaction(hash)
const hash = HASH // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.sendDelayedTransaction(hash)
const extra = EXTRA // (hex string, required), ex: '0199...c3ca'
xfg.getMessagesFromExtra(extra)
xfg.info() // get information about the block chain, including next block height
xfg.index() // get next block height
xfg.count() // get next block height
xfg.currencyId()
const height = HEIGHT // (integer, required), ex: 12750
xfg.blockHashByHeight(height) // get block hash given height
const height = HEIGHT // (integer, required), ex: 12750
xfg.blockHeaderByHeight(height) // get block header given height
const hash = HASH // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.blockHeaderByHash(hash) // get block header given hash
xfg.lastBlockHeader()
const hash = HASH // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.block(hash)
const height = HEIGHT // (integer, required), ex: 12750
xfg.blocks(height) // returns 31 blocks up to and including HEIGHT
const address = ADDRESS // destination address (string, required), ex: 'fireCd9...'
const reserveSize = RESERVE_SIZE // bytes to reserve in block for work, etc. (integer < 256, optional, default 14), ex: 255
const opts = {
  address: address,
  reserveSize: reserveSize
}
xfg.blockTemplate(opts)
const block = BLOCK // block blob (hex string, required), ex: '0300cb9eb...'
xfg.submitBlock(block)
const hash = HASH // (64-digit hex string, required), ex: '0ab1...3f4b'
xfg.transaction(hash)
const arr = [HASH1, HASH2, ...] // (array of 64-digit hex strings, required), ex: ['0ab1...3f4b']
xfg.transactions(arr)
xfg.transactionPool()
const transaction = TRANSACTION // transaction blob (hex string, required), ex: ''01d86301...'
xfg.sendRawTransaction(transaction)