JS API
Global Objects
console
The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.
The global console can be used without calling require('console').
console.info([...args])
...args <any>The console.info() function is an alias for
console.log().
console.log([...args])
...args <any>Print
argsto Nebulas Logger at levelinfo.
console.debug([...args])
...args <any>Print
argsto Nebulas Logger at leveldebug.
console.warn([...args])
...args <any>Print
argsto Nebulas Logger at levelwarn.
console.error([...args])
...args <any>Print
argsto Nebulas Logger at levelerror.
LocalContractStorage
The LocalContractStorage module provides a state trie based storage capability. It accepts string only key value pairs. And all data are stored to a private state trie associated with current contract address, only the contract can access them.
BigNumber
The BigNumber module use the bignumber.js, a JavaScript library for arbitrary-precision decimal and non-decimal arithmetic. The contract can use BigNumber directly to handle the value of the transaction and other values transfer.
Blockchain
The Blockchain module provides a object for contracts to obtain transactions and blocks executed by the current contract. Also, the NAS can be transferred from the contract and the address check is provided.
Blockchain API:
properties:
block: current block for contract executiontimestamp: block timestamphash: block hashheight: block height
transaction: current transaction for contract executionhash: transaction hashfrom: transaction from addressto: transaction to addressvalue: transaction value, a BigNumber object for contract usenonce: transaction noncetimestamp: transaction timestampgasPrice: transaction gasPrice, a BigNumber object for contract usegasLimit: transaction gasLimit, a BigNumber object for contract use
transfer(address, value): transfer NAS from contract to addressparams:
address: nebulas address to receive NASvalue: transfer value, a BigNumber object
return:
0: transfer success1: transfer failed
verifyAddress(address): verify addressparams:
address: address need to check
return:
1: address is valid0: address is invalid
Example to use:
Event
The Event module records execution events in contract. The recorded events are stored in the event trie on the chain, which can be fetched by FetchEvents method in block with the execution transaction hash. All contract event topics have a chain.contract. prefix before the topic they set in contract.
topic: user-defined topicobj: JSON object
You can see the example in SampleContract before.
Last updated