Introduction
Technical
tutorials
Firechain.js is a JavaScript library for interacting with the Firechain network. It provides a set of simple APIs for things like sending transactions, querying the state of the blockchain, and deploying smart contracts, as well as a set of utility functions for encoding and decoding data. It also provides a set of networking modules for connecting to Firechain nodes.
Firechain.js is available as an ES6 module and can be used in both Node.js and the browser.
Firechain.js is available as an npm package. We recommend using yarn to install it.
Firechain.js is available as an ES6 module. You can import it as follows:
If you are using CommonJS, you can use the require
syntax instead:
The ABI is the interface between the contract and the outside world. It defines the methods that can be called, and the events that can be emitted. It is also used to generate the contract's interface. Firechain uses a modified version of the Solidity Contract ABI specification.
Contract methods (including constructors, asynchronous calls, and queries) can contain arbitrary parameters, and they can also have multiple return values. Currently, the following parameter types are supported:
Type | Name | Example | Value | Encoded Value |
---|---|---|---|---|
uint<M> |
Unsigned integer, 0 < M <= 256, M % 8 == 0 | uint256 | '2345675643' | '000000000000000000000000000000000000000000000000000000008bd02b7b' |
int<M> |
Signed integer, 0 < M <= 256, M % 8 == 0 | int8 | '2' | '0000000000000000000000000000000000000000000000000000000000000002' |
uint |
Equivalent to uint256 | uint | '2345675643' | '000000000000000000000000000000000000000000000000000000008bd02b7b' |
int |
Equivalent to int256 | int | '2' | '0000000000000000000000000000000000000000000000000000000000000002' |
tokenId |
Token id | tokenId | 't5649544520544f4b454e6e40' | '000000000000000000000000000000000000000000005649544520544f4b454e' |
address |
Address of account | address | 'fire:010000000000000000000000000000000000000063bef3da00' | '0000000000000000000000010000000000000000000000000000000000000000' |
gid |
Consensus group id | gid | '01000000000000000000' | '0000000000000000000000000000000000000000000001000000000000000000' |
bool |
Boolean | bool | true | '0000000000000000000000000000000000000000000000000000000000000001' |
bytes<M> |
Fixed-length byte array, 0 < M <= 32 | bytes32 | '0x0100000000000000000000000000000000000000000000000000000000000000' | '0100000000000000000000000000000000000000000000000000000000000000' |
bytes |
Variable-length byte array | bytes | '0xdf3234' | '00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003df32340000000000000000000000000000000000000000000000000000000000' |
string |
Variable-length string | string | 'foobar' | '0000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000' |
<type>[M] |
Fixed-length array of type, M >= 0. Range of values:uint<M> , int<M> , uint , int , tokenId , address , gid , bool and string |
uint8[2] | ['1','2'] | '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002' |
<type>[] |
Variable-length array of type. Range of values: uint<M> , int<M> , uint , int , tokenId , address , gid , bool and string |
uint256[] | ['1','2'] | '000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002' |
Parameters
jsonInterface | Array<jsonInterface>
eventName?
Name of method to encode, required if the first parameter is a jsonInterface
array.Return
hexString
Example
Parameters
jsonInterface | Array<jsonInterface>
methodName?
Name of method to encode, required if the first parameter is a jsonInterface
array.Return
hexString
Example
Parameters
jsonInterface | Array<jsonInterface>
params
Input parametersmethodName?
Name of method to encode, required if the first parameter is a jsonInterface
array.Return
hexString
Example
Parameters
type
Parameter typeparams
Input parameters. If the parameter type is array, an parameter array should be passed inReturn
hexString
Example
Parameters
type
Parameter typehexString
Encoded hex stringReturn
decodeResult
Example
Parameters
jsonInterface | Array<type-string> | Array<jsonInterface>
params<Array | json-string>
Input parametersmethodName?
Name of method to encode, required if the first parameter is an array.Return
hexString
Example
Parameters
jsonInterface | Array<type-string> | Array<jsonInterface>
hexString
Encoded hex stringmethodName?
Name of method to decode, required if the first parameter is an array.Return
decodeResult
Example
Parameters
jsonInterface.inputs | jsonInterface | Array<jsonInterface>
hexString
Encoded hex stringArray<hexString>
eventName?
Name of event to decode, required if the first parameter is a jsonInterface
array.Return
decodeResult
Example