Skip to content

blockchaingate/kblib

Repository files navigation

Kanban Javascript API (Kblib)

Kblib is a library designed to help with development on the kanban network, whether it is to interface with a kanban node, or to perform some common offline tasks such as signing transactions.

Kblib is made up of two main parts:

  1. Kblib.kanban - Involves interfacing with a kanban network. Requires a kanban node to connect to.
  2. Kblib._extend - Offline tools common for wallet and dapp development (not requiring a kanban node). Subdivided into sections called offline/utils/coders.

Set-up and Transaction Signing Example

const Kblib = require('./kblib');

const kblib = new Kblib();

// Offline methods - ready to go out of the box. Example creates a sendtocontract transaction.
const derivedKeys = kblib._extend.offline.deriveFromMnemonic('<12_word_seed_phrase_goes_here>');

const transactionObject = {
  nonce: <account>,
  gasPrice: '0x2FAF080',
  gasLimit: '0x1E8480',
  data: '<bytecode_goes_here>',
  value: '0x0'
}
const signedTransaction = kblib._extend.offline.signTransaction(transactionObject, derivedKeys.privateKey, 'MAINNET');

// Kanban methods - requires setting up a provider to access kanban node - IPC or HTTP provider

// IPC provider
const provider = new Kblib.providers.IpcProvider(<path to geth.ipc file on kanban node>, net);
kblib.setProvider(provider, null, { defaultBlock: 'latest' });

// OR

// HTTP Provider
const provider = new Kblib.providers.HttpProvider('http://localhost:8545', net);
kblib.setProvider(provider, null, { defaultBlock: 'latest' });


// Using the now-connected node to submit a transaction to the network

kblib.kanban.sendRawTransaction(signedTransaction, callbackFunction);

kblib documentation

Table of Contents

Kblib

sha3

kblib.sha3(stringToHash)

Will calculate the keccak256 of the input.

Parameters

  • stringToHash - String - The string to be hashed

Return Type

  • String - sha3/keccak256 hashed version of stringToHash

Back to top

Kblib.kanban

Properties

Property Return-type Description
settings Object contains properties set for this instance of the module
kanban.coinbase String the coinbase address to which mining rewards will go
kanban.mining Boolean checks whether the node is mining or not
kanban.hashrate Number number of hashes per second that the node is mining with
kanban.syncing syncing object or boolean if node is syncing, returns syncing object, otherwise false
kanban.gasPrice BigNumber current gas price oracle determined by median of last few blocks
kanban.accounts array of String array of addresses controlled by node
kanban.blockNumber Object object containing "blockNumber" and "blockNumberHex"
kanban.protocolVersion String protocol version of the node in hexadecimal format
version.network String which kanban network the node is a part of
net.peerCount Number Returns number of peers currently connected to the client
net.listening Boolean Returns true if client is listening for network connections.

Back to top

kanban.getBlock

kblib.kanban.getBlock(blockHashOrBlockNumber [, returnTransactionObjects])

Returns a block matching the block number or block hash.

Parameters

  • blockHashOrBlockNumber - String|Number - The block number or block hash. Or the string "genesis", "latest" or "pending" as in the default block parameter.
  • returnTransactionObjects - Boolean - (optional, default false) If true, the returned block will contain all transactions as objects, if false it will only contains the transaction hashes.

Return Type

  • block object:
    • number - Number: The block number. null when its pending block.
    • hash 32 Bytes - String: Hash of the block. null when its pending block.
    • parentHash 32 Bytes - String: Hash of the parent block.
    • nonce 8 Bytes - String: Hash of the generated proof-of-work. null when its pending block.
    • sha3Uncles 32 Bytes - String: SHA3 of the uncles data in the block.
    • logsBloom 256 Bytes - String: The bloom filter for the logs of the block. null when its pending block.
    • transactionsRoot 32 Bytes - String: The root of the transaction trie of the block
    • stateRoot 32 Bytes - String: The root of the final state trie of the block.
    • receiptsRoot 32 Bytes - String: Transaction receipts are used to store the state after a transaction has been executed and are kept in an index-keyed trie. The hash of its root is placed in the block header as the receipts root.
    • miner - String: The address of the beneficiary to whom the mining rewards were given.
    • difficulty - String: Integer of the difficulty for this block.
    • totalDifficulty - String: Integer of the total difficulty of the chain until this block.
    • extraData - String: The “extra data” field of this block.
    • size - Number: Integer the size of this block in bytes.
    • gasLimit - Number: The maximum gas allowed in this block.
    • gasUsed - Number: The total used gas by all transactions in this block.
    • timestamp - Number: The unix timestamp for when the block was collated.
    • transactions - Array: Array of transaction objects, or 32 Bytes transaction hashes depending on the returnTransactionObjects parameter.

Back to top

kanban.getTransaction

kblib.kanban.getTransaction(transactionHash)

Returns a transaction matching the given transaction hash.

Parameters

  • transactionHash - String - The hash of the transaction to be looked up

Return Type

  • transaction Object:
    • hash 32 Bytes - String: Hash of the transaction.
    • nonce - Number: The number of transactions made by the sender prior to this one.
    • blockHash 32 Bytes - String: Hash of the block where this transaction was in. null when its pending.
    • blockNumber - Number: Block number where this transaction was in. null when its pending.
    • transactionIndex - Number: Integer of the transactions index position in the block. null when its pending.
    • from - String: Address of the sender.
    • to - String: Address of the receiver. null when its a contract creation transaction.
    • value - String: Value transferred in wei.
    • gasPrice - String: The wei per unit of gas provided by the sender in wei.
    • gas - Number: Gas provided by the sender.
    • input - String: The data sent along with the transaction.

kanban.getTransactionFromBlock

kblib.kanban.getTransactionFromBlock(blockHashOrBlockNumber, indexNumber)

Returns a transaction based on a block hash or number and the transactions index position.

Parameters

  • blockHashOrBlockNumber - String|Number - The hash or block number of the block containing the transaction
  • indexNumber - Number - The index of the transaction within the block

Return Type

  • transaction Object:
    • hash 32 Bytes - String: Hash of the transaction.
    • nonce - Number: The number of transactions made by the sender prior to this one.
    • blockHash 32 Bytes - String: Hash of the block where this transaction was in. null when its pending.
    • blockNumber - Number: Block number where this transaction was in. null when its pending.
    • transactionIndex - Number: Integer of the transactions index position in the block. null when its pending.
    • from - String: Address of the sender.
    • to - String: Address of the receiver. null when its a contract creation transaction.
    • value - String: Value transferred in wei.
    • gasPrice - String: The wei per unit of gas provided by the sender in wei.
    • gas - Number: Gas provided by the sender.
    • input - String: The data sent along with the transaction.

Back to top

kanban.getTransactionReceipt

kblib.kanban.getTransactionReceipt(transactionHash)

Returns the receipt of a transaction by transaction hash.

Parameters

  • transactionHash - String - The hash of the transaction to be looked up

Return Type

  • transaction receipt Object | null:
    • status - Boolean: TRUE if the transaction was successful, FALSE, if the EVM reverted the transaction.
    • blockHash 32 Bytes - String: Hash of the block where this transaction was in.
    • blockNumber - Number: Block number where this transaction was in.
    • transactionHash 32 Bytes - String: Hash of the transaction.
    • transactionIndex- Number: Integer of the transactions index position in the block.
    • from - String: Address of the sender.
    • to - String: Address of the receiver. null when its a contract creation transaction.
    • contractAddress - String: The contract address created, if the transaction was a contract creation, otherwise null.
    • cumulativeGasUsed - Number: The total amount of gas used when this transaction was executed in the block.
    • gasUsed - Number: The amount of gas used by this specific transaction alone.
    • logs - Array: Array of log objects, which this transaction generated.

Back to top

kanban.pendingTransactions

kblib.kanban.pendingTransactions()

Returns a list of pending transactions.

Parameters

  • none

Return Type

  • Array of transaction objects:
    • hash 32 Bytes - String: Hash of the transaction.
    • nonce - Number: The number of transactions made by the sender prior to this one.
    • blockHash 32 Bytes - String: Hash of the block where this transaction was in. null when its pending.
    • blockNumber - Number: Block number where this transaction was in. null when its pending.
    • transactionIndex - Number: Integer of the transactions index position in the block. null when its pending.
    • from - String: Address of the sender.
    • to - String: Address of the receiver. null when its a contract creation transaction.
    • value - String: Value transferred in wei.
    • gasPrice - String: The wei per unit of gas provided by the sender in wei.
    • gas - Number: Gas provided by the sender.
    • input - String: The data sent along with the transaction.

Back to top

kanban.getTransactionCount

kblib.kanban.getTransactionCount(address [, defaultBlock])

Get the numbers of transactions sent from this address.

Parameters

  • address - String - The address that you want to see the transaction count of
  • blockNumber - String|Number - (optional, default "latest") The block number in decimal or hex format. Or the string "genesis", "latest" or "pending".

Return Type

  • Number - The number of transactions sent from the address in the given (or latest) block

Back to top

kanban.getBlockTransactionCount

kblib.kanban.getBlockTransactionCount(blockHashOrBlockNumber)

Returns the number of transaction in a given block.

Parameters

  • blockHashOrBlockNumber - String|Number - The block number or block hash. Or the string "genesis", "latest" or "pending" as in the default block parameter.

Return Type

  • Number - The number of transactions in the given block

Back to top

kanban.getUncle

kblib.kanban.getUncle(blockHashOrBlockNumber, uncleIndex)

Returns a blocks uncle by a given uncle index position.

Parameters

  • blockHashOrBlockNumber - String|Number - The hash or block number. Or the string "genesis", "latest" or "pending" as in the default block parameter.
  • uncleIndex - Number - The index position of the uncle

Return Type

  • block object:
    • number - Number: The block number. null when its pending block.
    • hash 32 Bytes - String: Hash of the block. null when its pending block.
    • parentHash 32 Bytes - String: Hash of the parent block.
    • nonce 8 Bytes - String: Hash of the generated proof-of-work. null when its pending block.
    • sha3Uncles 32 Bytes - String: SHA3 of the uncles data in the block.
    • logsBloom 256 Bytes - String: The bloom filter for the logs of the block. null when its pending block.
    • transactionsRoot 32 Bytes - String: The root of the transaction trie of the block
    • stateRoot 32 Bytes - String: The root of the final state trie of the block.
    • receiptsRoot 32 Bytes - String: Transaction receipts are used to store the state after a transaction has been executed and are kept in an index-keyed trie. The hash of its root is placed in the block header as the receipts root.
    • miner - String: The address of the beneficiary to whom the mining rewards were given.
    • difficulty - String: Integer of the difficulty for this block.
    • totalDifficulty - String: Integer of the total difficulty of the chain until this block.
    • extraData - String: The “extra data” field of this block.
    • size - Number: Integer the size of this block in bytes.
    • gasLimit - Number: The maximum gas allowed in this block.
    • gasUsed - Number: The total used gas by all transactions in this block.
    • timestamp - Number: The unix timestamp for when the block was collated.
    • transactions - Array: Array of transaction objects, or 32 Bytes transaction hashes depending on the returnTransactionObjects parameter.

Back to top

kanban.getUncleCount

kblib.kanban.getUncleCount(blockHashOrBlockNumber)

Returns then number of uncles for a given block.

Parameters

  • blockHashOrBlockNumber - String|Number - The hash or block number. Or the string "genesis", "latest" or "pending" as in the default block parameter. If left blank, this method will not default to anything.

Return Type

  • Number : The chosen block's uncle count

Back to top

kanban.getBalance

kblib.kanban.getBalance(address [, defaultBlock])

Get the balance of an address at a given block.

Parameters

  • address - String - The address to get the balance of
  • defaultBlock - Number|String - (optional) - if you pass this parameter it will not use the default block set with kblib.kanban.defaultBlock.

Return Type

  • balance object:
    • BTC - String - The Bitcoin balance in hexadecimal format
    • ETH - String - The Ether balance in hexadecimal format
    • FAB - String - The FABcoin balance in hexadecimal format

Back to top

kanban.sendRawTransaction

kblib.kanban.sendRawTransaction(signedTransactionData)

Sends an already signed transaction, generated for example using kblib.kanban.accounts.signTransaction

Parameters

  • signedTransactionData - String - signed transaction data in hex format

Return Type

  • String - 32 byte hash of the transaction

Back to top

kanban.getStorageAt

kblib.kanban.getStorageAt(address, position [, defaultBlock])

Get the storage at a specific position of an address.

Parameters

  • address - String - The address to get the storage from.
  • position - Number - The index position of the storage.
  • defaultBlock - String|Number - (optional, default "latest") The block number in decimal or hex format. Or the string "genesis", "latest" or "pending".

Return Type

  • String - The value in storage at the given position, as a hex string

Back to top

kanban.getCode

kblib.kanban.getCode(address [, defaultBlock])

Get the code at a specific address.

Parameters

  • address - String - The address of the smart contract
  • defaultBlock - String|Number - (optional, default "latest") The block number in decimal or hex format. Or the string "genesis", "latest" or "pending".

Return Type

  • String - The code at the given address, as a hex string

Back to top

kanban.call

kblib.kanban.call(callObject [, defaultBlock])

Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

Parameters

  • callObject - transaction Object - The transaction object to send:
    • from - String|Number: (optional) The address for the sending account. Uses the kblib.kanban.defaultAccount property, if not specified. Or an address or index of a local wallet in kblib.kanban.accounts.wallet.
    • to - String: (optional) The destination address of the message, left undefined for a contract-creation transaction.
    • coin - String (optional) The type of coin you wish to send. Currently supports ("FAB", "BTC", "ETH"). Default "FAB".
    • value - Number|String|BN|BigNumber: (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
    • gas - Number: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).
    • gasPrice - Number|String|BN|BigNumber: (optional) The price of gas for this transaction in wei, defaults to kblib.kanban.gasPrice.
    • data - String: (optional) Either a ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialization code.
    • nonce - Number: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
  • defaultBlock - String|Number - (optional, default "latest") The block number in decimal or hex format. Or the string "genesis", "latest" or "pending".

Return Type

  • String - The returned data of the call, e.g. a smart contract functions return value.

Back to top

kanban.estimateGas

kblib.kanban.estimateGas(callObject)

Executes a message call or transaction and returns the amount of the gas used.

Parameters

  • callObject - transaction Object - The transaction object to send:
    • from - String|Number: (optional) The address for the sending account. Uses the kblib.kanban.defaultAccount property, if not specified. Or an address or index of a local wallet in kblib.kanban.accounts.wallet.
    • to - String: (optional) The destination address of the message, left undefined for a contract-creation transaction.
    • coin - String (optional) The type of coin you wish to send. Currently supports ("FAB", "BTC", "ETH"). Default "FAB".
    • value - Number|String|BN|BigNumber: (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.
    • gas - Number: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).
    • gasPrice - Number|String|BN|BigNumber: (optional) The price of gas for this transaction in wei, defaults to kblib.kanban.gasPrice.
    • data - String: (optional) Either a ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialization code.
    • nonce - Number: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.

Return Type

  • Number - The amount of gas used in the simulated execution of the call

Back to top

kanban.getWork

kblib.kanban.getWork()

Executes a message call or transaction and returns the amount of the gas used.

Parameters

  • none

Return Type

  • Array (3 elements) :
    • String (32 Bytes) at index 0: current block header pow-hash
    • String (32 Bytes) at index 1: the seed hash used for the DAG.
    • String (32 Bytes) at index 2: the boundary condition (“target”), 2^256 / difficulty.

Back to top

kanban.submitWork

kblib.kanban.submitWork(callObject)

Executes a message call or transaction and returns the amount of the gas used.

Parameters

  • nonce - String (8 Bytes) - The nonce found (64 bits)
  • powHash - String (32 Bytes) - The header’s pow-hash (256 bits)
  • digest - String (32 Bytes) - The mix digest (256 bits)

Return Type

  • Boolean - Returns true if the provided solution is valid, otherwise false.

Back to top

kanban.getLogs

kblib.kanban.getLogs(options)

Returns an array of all logs matching a given filter object.

Parameters

  • filter object::
    • fromBlock - Number|String - (optional, default 'latest') integer block number or 'latest', 'pending', or 'earliest'
    • toBlock - Number|String - (optional, default 'latest') integer block number or 'latest', 'pending', or 'earliest'
    • address - String|Array - (optional) Contract address or a list of addresses from which logs should originate.
    • topics - Array of String- (optional) array of 32 Byte topic strings. Topics are order-dependent. Each topic can also be an array of String with "or" options
    • blockhash - String (32 Byte hex) - (optional) Restricts the logs returned to the single block with the 32-byte hash blochHash. using blockHash is equivalent to fromBlock = toBlock = the block number with hash blockHash. In order to use blockHash, fromBlock and toBlock must not be specified.

Return Type

  • Array of log objects:
    • for filters created with kanban_newBlockFilter, the returned are block hashes (32 Byte hex string)
    • for filters created with kanban_newPendingTransactionFilter, the returned are transaction hashes (32 Byte hex string)
    • for filters created with kanban_newFilter logs are objects with the following parameters:
      • type - String - 'pending' when the log is pending, 'mined' if log is already mined
      • logIndex - Number - integer of the transactions index position log was created from. null when its pending log.
      • transactionHash - String - (32 Byte hex string) - hash of the transactions this log was created from. null when its pending log.
      • blockHash - String (32 Byte hex string ) - hash of the block this log was in. null when its pending. null when its pending log.
      • blockNumber - Number - the block number this log was in. null when its pending. null when its pending log.
      • address - String (20 Byte hex string) - address from which this log originated
      • data - String - contains one or more 32 Byte non-indexed arguments of the log.
      • topics - Array of String - Array of 0 to 4 32 Byte strings of indexed log arguments.

Back to top

Kblib._extend.offline

offline.deriveFromMnemonic

kblib._extend.offline.deriveFromMnemonic(mnemonic [, network])

Takes a mnemonic string and derives a set of keys and addresses.

Parameters

  • mnemonic - String - 12+ word space-separated mnemonic string used to seed the private key and other data.
  • network - String - (optional, default 'MAINNET') Can be 'MAINNET' or 'TESTNET'.

Return Type

  • Object:
    • privateKey - hex string - Private key generated from the mnemonic, in hexadecimal format.
    • privateKeyWIF - Private key generated from the mnemonic, in Wallet Import Format (WIF).
    • publicKey - Compressed public key derived from this private key.
    • address - The ethereum-style kanban address in hex, derived from this public key.

Back to top

offline.signTransaction

kblib._extend.offline.signTransaction(transactionObject, privateKey [, network])

RECOMMENDED

Takes a supplied transaction object and returns a signed transaction using the supplied private key. This signing is done locally, and is more secure than kanban.signTransaction.

Parameters

  • transactionObject: - String - 12+ word space-separated mnemonic string used to seed the private key and other data.
    • nonce - number or hex string - Desired nonce for the transaction. Typically this will be equal to the value returne by kanban.getTransactionCount, but can be higher. Transactions of an account are mined in order of increasing nonce..
    • gasPrice - number or hex string - Desired gas price for the transaction.
    • gasLimit - number or hex string - Desired gas limit for the transaction. If this is too low the transaction may fail, depending on the contract.
    • to - hex string - (semi-optional, default - none) Recipient Address. Omit for contract creation. Otherwise required.
    • data - hex string - (semi-optional, default '0x0') Omit if "send" transaction. Otherwise recommended to include.
    • value - hex string - (semi-optional, default '0x0') Required if "send" transaction. Otherwise only include if calling a payable function in contract, or it can be used by the constructor if deploying smart contract.
  • privateKey - String - Private key in hexadecimal format. Can be generated via offline.deriveFromMnemonic.
  • network - String - (optional, default 'MAINNET') Can be 'MAINNET' or 'TESTNET'.

Return Type

Back to top

Kblib._extend.utils

utils.padLeft

kblib._extend.utils.padLeft(string, characterAmount [, sign])

Adds a padding on the left of a string, Useful for adding paddings to HEX strings.

Parameters

  • string - String - The string to add padding on the left
  • characterAmount - Number - The number of characters the total string should have
  • sign - String - (optional, default '0') The character sign to use

Return Type

  • String - The padded string

Back to top

utils.padRight

kblib._extend.utils.padRight(string, characterAmount [, sign])

Adds a padding on the right of a string, Useful for adding paddings to HEX strings.

Parameters

  • string - String - The string to add padding on the left
  • characterAmount - Number - The number of characters the total string should have
  • sign - String - (optional, default '0') The character sign to use

Return Type

  • String - The padded string

Back to top

utils.toHex

kblib._extend.utils.toHex(mixed)

Will auto convert any given value to HEX. Number strings will interpreted as numbers. Text strings will be interpreted as UTF-8 strings.

Parameters

  • mixed - String|Number|BN|BigNumber - The input to convert to hex.

Return Type

  • String - The resulting hex string

Back to top

utils.toDecimal

kblib._extend.utils.toDecimal(hex)

Returns the number representation of a given HEX value. This is not useful for big numbers

Parameters

  • hexString - String|HEX - A string to convert to decimal representation

Return Type

  • Number - The decimal representation of the hex string

Back to top

utils.fromDecimal

kblib._extend.utils.fromDecimal(number)

Returns the HEX representation of a given number value.

Parameters

  • number - String|Number|BN|BigNumber - A number as a string or number

Return Type

  • String - A hex string representation of the number

Back to top

utils.toUtf8

kblib._extend.utils.toUtf8(hex)

Returns the UTF-8 string representation of a given HEX value.

Parameters

  • hex - String - A hex string to convert to a UTF-8 string

Return Type

  • String - The UTF-8 string

Back to top

utils.toAscii

kblib._extend.utils.toAscii(hex)

Returns the ASCII string representation of a given HEX value.

Parameters

  • hex - String - A hex string to convert to an ASCII string

Return Type

  • String - The ASCII string

Back to top

utils.fromUtf8

kblib._extend.utils.fromUtf8(string)

Returns the HEX representation of a given UTF-8 string.

Parameters

  • string - String - A UTF-8 string to convert to as hex string.

Return Type

  • String - The hex string

Back to top

utils.fromAscii

kblib._extend.utils.fromAscii(string [, length])

Returns the HEX representation of a given ASCII string. If you would like to transform an ASCII string into a valid bytes4, bytes8 etc. value then please pass the correct length as the second parameter

Parameters

  • string - String - The ASCII string to convert to a hex string
  • length - Number - (optional, default 32) The length of the returned hex string.

Return Type

  • String - The hex string

Back to top

utils.toWei

kblib._extend.utils.toWei(number [, unit])

Converts any ether value into wei // TO DO: change this?

Parameters

  • number - String|BN - The value in the unit provided
  • unit - String - (optional, default 'ether') The ether value to convert from. Possible values omitted.

Return Type

  • String | BN - If a string is given, it returns a number string, otherwise returns a BN.js instance

Back to top

utils.fromWei

kblib._extend.utils.fromWei(number [, unit])

Converts any wei value into an ether value.

Parameters

  • number - String|BN - The value in wei
  • unit - String - (optional, default 'ether') The ether value to convert to. Possible values omitted.

Return Type

  • String - It always returns a string number.

Back to top

utils.toBigNumber

kblib._extend.utils.toBigNumber(number)

Convert a number from various forms to to a BigNumber

Parameters

  • number - String|Number|Hex - Parameter Description

Return Type

  • BigNumber - BigNumber format of the number

Back to top

utils.toTwosComplement

kblib._extend.utils.toTwosComplement()

Converts a negative number into a two’s complement.

Parameters

  • number - Number|String|BigNumber - The number to convert.

Return Type

  • String - The converted hex string

Back to top

utils.isBigNumber

kblib._extend.utils.isBigNumber(bigNumber)

Description goes here

Parameters

  • bigNumber - BigNumber Object - A BigNumber.js instance

Return Type

  • Boolean - true if bigNumber is a an instance of BigNumber

Back to top

utils.isStrictAddress

kblib._extend.utils.isStrictAddress(address [, chainId])

Checks if a given string is a valid Kanban address, including the requirement that begin wit '0x'. It will also check the checksum, if the address has both upper and lowercase letters.

Parameters

  • address - String - An address string
  • chainId - Number - Chain id where checksummed address should be valid, defaults to null.

Return Type

  • Boolean - true if the address is valid and prefixed with '0x'

Back to top

utils.isAddress

kblib._extend.utils.isAddress(address [, chainId])

Checks if a given string is a valid Kanban address. It will also check the checksum, if the address has both upper and lowercase letters.

Parameters

  • address - String - An address string
  • chainId - Number - Chain id where checksummed address should be valid, defaults to null.

Return Type

  • Boolean - true if the address is valid

Back to top

utils.isChecksumAddress

kblib._extend.utils.isChecksumAddress(address)

Checks if a given string is a valid Kanban address and ikf the address has both upper and lowercase letters.

Parameters

  • address - String - An address string

Return Type

  • Boolean - true if the address is valid and contains mixed case

Back to top

utils.toChecksumAddress

kblib._extend.utils.toChecksumAddress(address [, chainId])

Will convert an upper or lowercase Kanban address to a checksum address.

Parameters

  • address - String - An address string
  • chainId - Number - Chain id where checksummed address should be valid, defaults to null.

Return Type

  • String - The checksum address

Back to top

utils.isFunction

kblib._extend.utils.isFunction(function)

Checks if the passed parameter is a function

Parameters

  • function - Object|other - The object you wish to verify is a function

Return Type

  • Boolean - true if the passed parameter is a function

Back to top

utils.isString

kblib._extend.utils.isString(string)

Checks if the passed parameter is a string

Parameters

  • string - String|other - some passed parameter

Return Type

  • Boolean - true if the passed parameter is a String

Back to top

utils.isObject

kblib._extend.utils.isObject(object)

Checks if the passed parameter is an object

Parameters

  • object - Object|other - some passed parameter

Return Type

  • Boolean - true if the passed parameter is an Object

Back to top

utils.isBoolean

kblib._extend.utils.isBoolean(boolean)

Checks if the passed parameter is a boolean

Parameters

  • boolean - Boolean|other - some passed parameter

Return Type

  • Boolean - true if the passed parameter is a Boolean

Back to top

utils.isArray

kblib._extend.utils.isArray(array)

Checks if the passed parameter is an array

Parameters

  • array - Array|other - some passed parameter

Return Type

  • Boolean - true if the passed parameter is an Array

Back to top

utils.isJson

kblib._extend.utils.isString(string)

Checks if the passed parameter is a valid JSON string

Parameters

  • string - String|other - some passed parameter

Return Type

  • Boolean - true if the passed parameter is valid JSON string

Back to top

Kblib.coders

coders.encodeParam

kblib._extend.coders.encodeParam(type, param)

Encodes one parameter for use in a smart contract ABI

Parameters

  • type - String - The type of the parameter to be encoded for the ABI
  • param - String - The parameter to be encoded

Return Type

  • String - The ABI-encoded parameter

Back to top

coders.encodeParams

kblib._extend.coders.encodeParams(types, params)

Encodes an array of parameters for use in a smart contract ABI

Parameters

  • types - Array of String - The types of the parameters to be encoded for the ABI
  • params - Array of String - The parameters to be encoded, in order

Return Type

  • String - The ABI-encoded parameters

Back to top

coders.decodeParam

kblib._extend.coders.decodeParam(type, bytes)

Decodes an ABI encoded parameter to its JavaScript type.

Parameters

  • type - String - The JavaScript type of the parameter
  • bytes - String - The encoded parameter to be decoded

Return Type

  • various types - The ABI-decoded parameter. Type depends on the one supplied

Back to top

coders.decodeParams

kblib._extend.coders.decodeParams(types, bytes)

Decodes ABI encoded parameters to their JavaScript types.

Parameters

  • types - Array of String - The JavaScript type of the parameters
  • bytes - String - A string of the encoded parameters to be decoded

Return Type

  • Array of various types - The ABI-decoded parameters. Types depend on the ones supplied.

Back to top

coders.encodeFunctionSignature

kblib._extend.coders.encodeFunctionSignature(functionName, types)

Encodes the function name to its ABI signature, which are the first 4 bytes of the sha3 hash of the function name including types.

Parameters

  • functionName - String - the name of the function
  • types - Array of String | String - The solidity types of the parameters in the function signature

Return Type

  • String - The ABI-encoded function signature (pre-pended with '0x')

Back to top

coders.encodeFunctionCall

kblib._extend.coders.encodeFunctionCall(functionName, types, params)

Encodes the function call for use with a contract ABI. which are the first 4 bytes of the sha3 hash of the function name including parameters.

Parameters

  • functionName - String - the name of the Function
  • types - Array of String | String - The solidity types of the parameters in the function signature
  • params - Array of String | String - The parameters to be used in the function call

Return Type

  • String - The ABI-encoded function call (pre-pended with '0x')

Back to top

About

Kanban library - Javascript library for Kanban blockchain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published