Class: API

API


new API(neb)

User API constructor. Class encapsulate methods for building distributed applications and services.
Parameters:
Name Type Description
neb Neb Instance of Neb library.
See:
Example
var api = new API ( new Neb() );
// or just
var api = new Neb().api;

Methods


getNebState()

Method get state of Nebulas Network.
See:
Returns:
Example
var api = new Neb().api;
api.getNebState().then(function(state) {
//code
});

latestIrreversibleBlock()

Method get latest irreversible block of Nebulas Network.
See:
Returns:
Example
var api = new Neb().api;
api.latestIrreversibleBlock().then(function(blockData) {
//code
});

getAccountState(options)

Method return the state of the account. Balance and nonce.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
address HexString
height String
See:
Returns:
Example
var api = new Neb().api;
api.getAccountState({address: "n1QsosVXKxiV3B4iDWNmxfN4VqpHn2TeUcn"}).then(function(state) {
//code
});

call(options)

Method wrap smart contract call functionality.
Parameters:
Name Type Description
options TransactionOptions
See:
Returns:
Example
var api = new Neb().api;
api.call({
   chainID: 1,
   from: "n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5",
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000,
   contract: {
       function: "save",
       args: "[0]"
   }
}).then(function(tx) {
    //code
});

sendRawTransaction(options)

Method wrap submit the signed transaction.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
data String
See:
Returns:
Example
var api = new Neb().api;
var tx = new Transaction({
   chainID: 1,
   from: acc1,
   to: acc2,
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
tx.signTransaction();
api.sendRawTransaction( {data: tx.toProtoString()} ).then(function(hash) {
//code
});

getBlockByHash(options)

Get block header info by the block hash.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
hash HexString
fullTransaction Boolean
See:
Returns:
Example
var api = new Neb().api;
api.getBlockByHash({
    hash: "00000658397a90df6459b8e7e63ad3f4ce8f0a40b8803ff2f29c611b2e0190b8",
    fullTransaction: true
}).then(function(block) {
//code
});

getBlockByHeight(options)

Get block header info by the block height.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
height Number
fullTransaction Boolean
See:
Returns:
Example
var api = new Neb().api;
api.getBlockByHeight({height:2, fullTransaction:true}).then(function(block) {
//code
});

getTransactionReceipt(options)

Get transactionReceipt info by tansaction hash.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
hash HexString
See:
Returns:
Example
var api = new Neb().api;
api.getTransactionReceipt({hash: "cc7133643a9ae90ec9fa222871b85349ccb6f04452b835851280285ed72b008c"}).then(function(receipt) {
//code
});

getTransactionByContract(options)

Get transactionReceipt info by contract address.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
address HexString contract address
See:
Returns:
the same as TransactionReceipt
Example
var api = new Neb().api;
api.getTransactionByContract({address: "n1sqDHGjYtX6rMqFoq5Tow3s3LqF4ZxBvE3"}).then(function(receipt) {
 //code
});

subscribe(options)

Return the subscribed events of transaction & block.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
topics Array | String
onDownloadProgress function On progress callback function. Recive chunk.
See:
Returns:
Example
var api = new Neb().api;
api.subscribe({topics: ["chain.linkBlock", "chain.pendingTransaction"]}).then(function(eventData) {
//code
});

gasPrice()

Return current gasPrice.
See:
Returns:
Example
var api = new Neb().api;
api.gasPrice().then(function(gasPrice) {
//code
});

estimateGas(options)

Return the estimate gas of transaction.
Parameters:
Name Type Description
options TransactionOptions
See:
Returns:
Gas
Example
var api = new Neb().api;
api.estimateGas({
   chainID: 1,
   from: "n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5",
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
}).then(function(gas) {
//code
});

getEventsByHash(options)

Return the events list of transaction.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
hash HexString
See:
Returns:
Example
var api = new Neb().api;
api.getEventsByHash({hash: "ec239d532249f84f158ef8ec9262e1d3d439709ebf4dd5f7c1036b26c6fe8073"}).then(function(events) {
//code
});

getDynasty(options)

Method getter for dpos dynasty.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
height Number
See:
Returns:
Example
var api = new Neb().api;
api.getDynasty({height: 1}).then(function(delegatees) {
//code
});