PWeb3 Javascript API
Getting Started
These docs are for PWeb3. To make your app work on Pchain, you can use the web3
object provided by the PWeb3 library. Under the hood, it communicates to a local node through RPC calls. PWeb3 works with any Pchain node which exposes an RPC layer.
Adding web3
First, you need to get web3.js into your project. This can be done using the following methods:
npm:
npm install pweb3
bower:
bower install pweb3
vanilla: link the
dist./pweb3.min.js
Then you need to create a web3 instance, setting a provider. To make sure you don't overwrite the already set provider when in mist, check first if the web3 is available:
After that, you can use the API of the web3
object.
Using callbacks
As this API is designed to work with a local RPC node, all its functions use synchronous HTTP requests by default. If you want to make an asynchronous request, you can pass an optional callback as the last parameter to most functions. All callbacks are using an error first callback style:
Batch requests
Batch requests allow queuing up requests and processing them at once. Note Batch requests are not faster! In fact making many requests at once will in some cases be faster, as requests are processed asynchronously. Batch requests are mainly useful to ensure the serial processing of requests.
A note on big numbers in web3.js
You will always get a BigNumber object for number values as JavaScript is not able to handle big numbers correctly. Look at the following examples:
web3.js depends on the BigNumber Library and adds it automatically.
The next example wouldn't work as we have more than 20 floating points, therefore it is recommended to always keep your balance in wei and only transform it to other units when presenting to the user:
PWeb3 API Reference
web3
version
net
pi
register(hexString) (Not implemented yet)
unRegister(hexString) (Not implemented yet)
db
shh
chain
tdm
del
Library
web3
The web3
object provides all methods.
Example
Example using HTTP Basic Authentication
web3.version.api
Returns
String
- The pchain js api version.
Example
web3.version.node
Returns
String
- The client/node version.
Example
web3.version.network
Returns
String
- The network protocol version.
Example
web3.version.pchain
Returns
String
- The pchain protocol version.
Example
web3.version.whisper
Returns
String
- The whisper protocol version.
Example
web3.isConnected
Should be called to check if a connection to a node exists
Parameters
none
Returns
Boolean
Example
web3.setProvider
Should be called to set provider.
Parameters
none
Returns
undefined
Example
web3.currentProvider
Will contain the current provider, if one is set. This can be used to check if mist etc. has set already a provider.
Returns
Object
- The provider set or null
;
Example
web3.reset
Should be called to reset state of web3. Resets everything except manager. Uninstalls all filters. Stops polling.
Parameters
Boolean
- Iftrue
it will uninstall all filters, but will keep the web3.pi.isSyncing() polls
Returns
undefined
Example
web3.sha3
Parameters
String
- The string to hash using the Keccak-256 SHA3 algorithmObject
- (optional) Setencoding
tohex
if the string to hash is encoded in hex. A leading0x
will be automatically ignored.
Returns
String
- The Keccak-256 SHA3 of the given data.
Example
web3.getVoteHash
Parameters
from
: address, 20 Bytes - the address who triggers the actionpubkey
: hex string, 128 Bytes - the BLS Public Key who triggers the action,How To Get Your Pubkeyamount
: hex string - the amount of votesalt
: string - salt string
Returns
String
- The Keccak-256 SHA3 of the given data.
Example
web3.toHex
Converts any value into HEX.
Parameters
String|Number|Object|Array|BigNumber
- The value to parse to HEX. If its an object or array it will beJSON.stringify
first. If its a BigNumber it will make it the HEX value of a number.
Returns
String
- The hex string of mixed
.
Example
web3.toAscii
Converts a HEX string into a ASCII string.
Parameters
String
- A HEX string to be converted to ascii.
Returns
String
- An ASCII string made from the given hexString
.
Example
web3.fromAscii
Converts any ASCII string to a HEX string.
Parameters
String
- An ASCII string to be converted to HEX.
Returns
String
- The converted HEX string.
Example
web3.toDecimal
Converts a HEX string to its number representation.
Parameters
String
- A HEX string to be converted to a number.
Returns
Number
- The number representing the data hexString
.
Example
web3.fromDecimal
Converts a number or number string to its HEX representation.
Parameters
Number|String
- A number to be converted to a HEX string.
Returns
String
- The HEX string representing of the given number
.
Example
web3.fromWei
Converts a number of wei into the following pchain units:
Gwei
Kwei
Mwei
/babbage
/pi
/femtoether
pi
finney
/gpi
/grand/gwei
kpi
/kwei
/lovelace
/mether
/micro
microether
/milli
/milliether
mwei
/nano
/nanoether
noether
picoether
/shannon
szabo
tpi
wei
Parameters
Number|String|BigNumber
- A number or BigNumber instance.String
- One of the above pi units.
Returns
String|BigNumber
- Either a number string, or a BigNumber instance, depending on the given number
parameter.
Example
web3.toWei
Converts an pchain unit into wei. Possible units are:
kwei
/ada
mwei
/babbage
gwei
/shannon
szabo
finney
pi
kpi
/grand
/einstein
mpi
gpi
tpi
Parameters
Number|String|BigNumber
- A number or BigNumber instance.String
- One of the above pi units.
Returns
String|BigNumber
- Either a number string, or a BigNumber instance, depending on the given number
parameter.
Example
web3.toBigNumber
Converts a given number into a BigNumber instance. See the note on BigNumber.
Parameters
Number|String
- A number, number string or HEX string of a number.
Returns
BigNumber
- A BigNumber instance representing the given value.
Example
web3.isAddress
Checks if the given string is an address.
Parameters
String
- A HEX string.
Returns
Boolean
- false
if it's not on a valid address format. Returns true
if it's an all lowercase or all uppercase valid address. If it's a mixed case address, it checks using web3.isChecksumAddress()
.
Example
web3.net.listening
This property is read only and says whether the node is actively listening for network connections or not.
Returns
Boolean
- true
if the client is actively listening for network connections, otherwise false
.
Example
web3.net.peerCount
This property is read only and returns the number of connected peers.
Returns
Number
- The number of peers currently connected to the client.
Example
web3.pi
Contains the pchain blockchain related methods.
Example
web3.pi.defaultAccount
This default address is used for the following methods (optionally you can overwrite it by specifying the from
property):
Values
String
, 20 Bytes - Any address you own, or where you have the private key for. Default is undefined
.
Returns
String
, 20 Bytes - The currently set default address.
Example
web3.pi.defaultBlock
This default block is used for the following methods (optionally you can override it by passing the defaultBlock parameter):
Values
Default block parameters can be one of the following:
Number
- a block numberString
-"earliest"
, the genesis blockString
-"latest"
, the latest block (current head of the blockchain)String
-"pending"
, the currently mined block (including pending transactions) Default islatest
Returns
Number|String
- The default block number to use when querying a state.
Example
web3.pi.syncing
This property is read only and returns the either a sync object, when the node is syncing or false
.
Returns
Object|Boolean
- A sync object as follows, when the node is currently syncing or false
:
startingBlock
:Number
- The block number where the sync started.currentBlock
:Number
- The block number where at which block the node currently synced to already.highestBlock
:Number
- The estimated block number to sync to.
Example
web3.pi.isSyncing
This convenience function calls the callback
everytime a sync starts, updates and stops.
Returns
Object
- a isSyncing object with the following methods:
syncing.addCallback()
: Adds another callback, which will be called when the node starts or stops syncing.syncing.stopWatching()
: Stops the syncing callbacks.
Callback return value
Boolean
- The callback will be fired withtrue
when the syncing starts and withfalse
when it stopped.Object
- While syncing it will return the syncing object:startingBlock
:Number
- The block number where the sync started.currentBlock
:Number
- The block number where at which block the node currently synced to already.highestBlock
:Number
- The estimated block number to sync to.
Example
web3.pi.coinbase
This property is read only and returns the coinbase address where the mining rewards go to.
Returns
String
- The coinbase address of the client.
Example
web3.pi.mining
This property is read only and says whether the node is mining or not.
Returns
Boolean
- true
if the client is mining, otherwise false
.
Example
web3.pi.hashrate
This property is read only and returns the number of hashes per second that the node is mining with.
Returns
Number
- number of hashes per second.
Example
web3.pi.gasPrice
This property is read only and returns the current gas price. The gas price is determined by the x latest blocks median gas price.
Returns
BigNumber
- A BigNumber instance of the current gas price in wei. See the note on BigNumber.
Example
web3.pi.accounts
This property is read only and returns a list of accounts the node controls.
Returns
Array
- An array of addresses controlled by client.
Example
web3.pi.blockNumber
This property is read only and returns the current block number.
Returns
Number
- The number of the most recent block.
Example
web3.pi.register
(Not Implemented yet) Registers the given address to be included in web3.pi.accounts
. This allows non-private-key owned accounts to be associated as an owned account (e.g., contract wallets).
Parameters
String
- The address to registerFunction
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
?
Example
web3.pi.unRegister
(Not Implemented yet) Unregisters a given address.
Parameters
String
- The address to unregister.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
?
Example
web3.pi.getBalance
Get the balance of an address at a given block.
Parameters
String
- The address to get the balance of.Number|String
- (optional) If you pass this parameter it will not use the default block set with web3.pi.defaultBlock.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- A BigNumber instance of the current balance for the given address in wei. See the note on BigNumber.
Example
web3.pi.getFullBalance
Get the balance of an address at a given block.
parameters
from
- address, 20 Bytes - address to check for balance.blockNumber
- QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending".fullProxied
- Boolean - If true it returns the full detail proxied object under this address.
returns
balance
- QUANTITY - integer of the current balance in p-wei. delegateBalance: QUANTITY - total delegate balance in p-wei to other address depositBalance: QUANTITY - deposit balance in p-wei for Validator Stake depositProxiedBalance: QUANTITY - total deposit proxied balance in p-wei for Validator Stake pendingRefundBalance: QUANTITY - total pending refund balance in p-wei which will be return to delegate at the end of Current Epoch proxiedBalance: QUANTITY - total proxied balance in p-wei delegate from other address proxied_detail: Object - detail record of each address's proxied data, including proxied balance, deposit proxied balance and pending refund balance.
example
web3.pi.getStorageAt
Get the storage at a specific position of an address.
Parameters
String
- The address to get the storage from.Number
- The index position of the storage.Number|String
- (optional) If you pass this parameter it will not use the default block set with web3.pi.defaultBlock.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The value in storage at the given position.
Example
web3.pi.getCode
Get the code at a specific address.
Parameters
String
- The address to get the code from.Number|String
- (optional) If you pass this parameter it will not use the default block set with web3.pi.defaultBlock.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The data at given address addressHexString
.
Example
web3.pi.getBlock
Returns a block matching the block number or block hash.
Parameters
String|Number
- The block number or hash. Or the string"earliest"
,"latest"
or"pending"
as in the default block parameter.Boolean
- (optional, defaultfalse
) Iftrue
, the returned block will contain all transactions as objects, iffalse
it will only contains the transaction hashes.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Object
- The block object:
number
:Number
- the block number.null
when its pending block.hash
:String
, 32 Bytes - hash of the block.null
when its pending block.parentHash
:String
, 32 Bytes - hash of the parent block.nonce
:String
, 8 Bytes - hash of the generated proof-of-work.null
when its pending block.sha3Uncles
:String
, 32 Bytes - SHA3 of the uncles data in the block.logsBloom
:String
, 256 Bytes - the bloom filter for the logs of the block.null
when its pending block.transactionsRoot
:String
, 32 Bytes - the root of the transaction trie of the blockstateRoot
:String
, 32 Bytes - the root of the final state trie of the block.miner
:String
, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.difficulty
:BigNumber
- integer of the difficulty for this block.totalDifficulty
:BigNumber
- 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 last given parameter.uncles
:Array
- Array of uncle hashes.
Example
web3.pi.getBlockTransactionCount
Returns the number of transaction in a given block.
Parameters
String|Number
- The block number or hash. Or the string"earliest"
,"latest"
or"pending"
as in the default block parameter.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Number
- The number of transactions in the given block.
Example
web3.pi.getUncle
Returns a blocks uncle by a given uncle index position.
Parameters
String|Number
- The block number or hash. Or the string"earliest"
,"latest"
or"pending"
as in the default block parameter.Number
- The index position of the uncle.Boolean
- (optional, defaultfalse
) Iftrue
, the returned block will contain all transactions as objects, iffalse
it will only contains the transaction hashes.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Object
- the returned uncle. For a return value see web3.pi.getBlock(). Note: An uncle doesn't contain individual transactions.
Example
web3.pi.getTransaction
Returns a transaction matching the given transaction hash.
Parameters
String
- The transaction hash.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Object
- A transaction object its hash transactionHash
:
hash
:String
, 32 Bytes - hash of the transaction.nonce
:Number
- the number of transactions made by the sender prior to this one.blockHash
:String
, 32 Bytes - 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
, 20 Bytes - address of the sender.to
:String
, 20 Bytes - address of the receiver.null
when its a contract creation transaction.value
:BigNumber
- value transferred in Wei.gasPrice
:BigNumber
- gas price provided by the sender in Wei.gas
:Number
- gas provided by the sender.input
:String
- the data sent along with the transaction.
Example
web3.pi.getTransactionFromBlock
Returns a transaction based on a block hash or number and the transactions index position.
Parameters
String
- A block number or hash. Or the string"earliest"
,"latest"
or"pending"
as in the default block parameter.Number
- The transactions index position.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Object
- A transaction object, see web3.pi.getTransaction:
Example
web3.pi.getTransactionReceipt
Returns the receipt of a transaction by transaction hash. Note That the receipt is not available for pending transactions.
Parameters
String
- The transaction hash.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Object
- A transaction receipt object, or null
when no receipt was found:
blockHash
:String
, 32 Bytes - hash of the block where this transaction was in.blockNumber
:Number
- block number where this transaction was in.transactionHash
:String
, 32 Bytes - hash of the transaction.transactionIndex
:Number
- integer of the transactions index position in the block.from
:String
, 20 Bytes - address of the sender.to
:String
, 20 Bytes - address of the receiver.null
when its a contract creation transaction.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.contractAddress
:String
- 20 Bytes - The contract address created, if the transaction was a contract creation, otherwisenull
.logs
:Array
- Array of log objects, which this transaction generated.status
:String
- '0x0' indicates transaction failure , '0x1' indicates transaction succeeded.
Example
web3.pi.getTransactionCount
Get the numbers of transactions sent from this address.
Parameters
String
- The address to get the numbers of transactions from.Number|String
- (optional) If you pass this parameter it will not use the default block set with web3.pi.defaultBlock.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Number
- The number of transactions sent from the given address.
Example
web3.pi.sendTransaction
Sends a transaction to the network.
Parameters
Object
- The transaction object to send:
from
:String
- The address for the sending account. Uses the web3.pi.defaultAccount property, if not specified.to
:String
- (optional) The destination address of the message, left undefined for a contract-creation transaction.value
:Number|String|BigNumber
- (optional) The value transferred for the transaction in Wei, also the endowment if it's a contract-creation transaction.gas
:Number|String|BigNumber
- (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).gasPrice
:Number|String|BigNumber
- (optional, default: To-Be-Determined) The price of gas for this transaction in wei, defaults to the mean network gas price.data
:String
- (optional) Either a byte string containing the associated data of the message, or in the case of a contract-creation transaction, the initialisation code.nonce
:Number
- (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The 32 Bytes transaction hash as HEX string. If the transaction was a contract creation use web3.pi.getTransactionReceipt() to get the contract address, after the transaction was mined.
Example
web3.pi.sendRawTransaction
Sends an already signed transaction. For example can be signed using: https://github.com/SilentCicero/pchainjs-accounts
Parameters
String
- Signed transaction data in HEX formatFunction
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The 32 Bytes transaction hash as HEX string. If the transaction was a contract creation use web3.pi.getTransactionReceipt() to get the contract address, after the transaction was mined.
Example
web3.pi.sign
Signs data from a specific account. This account needs to be unlocked.
Parameters
String
- Address to sign with.String
- Data to sign.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The signed data. After the hex prefix, characters correspond to ECDSA values like this:
Note that if you are using ecrecover
, v
will be either "00"
or "01"
. As a result, in order to use this value, you will have to parse it to an integer and then add 27
. This will result in either a 27
or a 28
.
Example
web3.pi.call
Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.
Parameters
Object
- A transaction object see web3.pi.sendTransaction, with the difference that for calls thefrom
property is optional as well.Number|String
- (optional) If you pass this parameter it will not use the default block set with web3.pi.defaultBlock.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The returned data of the call, e.g. a codes functions return value.
Example
web3.pi.estimateGas
Executes a message call or transaction, which is directly executed in the VM of the node, but never mined into the blockchain and returns the amount of the gas used.
Parameters
See web3.pi.sendTransaction, except that all properties are optional.
Returns
Number
- the used gas for the simulated call/transaction.
Example
web3.pi.filter
Parameters
String|Object
- The string"latest"
or"pending"
to watch for changes in the latest block or pending transactions respectively. Or a filter options object as follows:
fromBlock
:Number|String
- The number of the earliest block (latest
may be given to mean the most recent andpending
currently mining, block). By defaultlatest
.toBlock
:Number|String
- The number of the latest block (latest
may be given to mean the most recent andpending
currently mining, block). By defaultlatest
.address
:String
- An addressor a list of addressesto only get logs from particular account(s).topics
:Array of Strings
- An array of values which must each appear in the log entries. The order is important, if you want to leave topics out usenull
, e.g.[null, '0x00...']
. You can also pass another array for each topic with options for that topic e.g.[null, ['option1', 'option2']]
Returns
Object
- A filter object with the following methods:
filter.get(callback)
: Returns all of the log entries that fit the filter.filter.watch(callback)
: Watches for state changes that fit the filter and calls the callback. See this note for details.filter.stopWatching()
: Stops the watch and uninstalls the filter in the node. Should always be called once it is done.
Watch callback return value
String
- When using the"latest"
parameter, it returns the block hash of the last incoming block.String
- When using the"pending"
parameter, it returns a transaction hash of the most recent pending transaction.Object
- When using manual filter options, it returns a log object as follows:logIndex
:Number
- integer of the log index position in the block.null
when its pending log.transactionIndex
:Number
- integer of the transactions index position log was created from.null
when its pending log.transactionHash
:String
, 32 Bytes - hash of the transactions this log was created from.null
when its pending log.blockHash
:String
, 32 Bytes - hash of the block where this log was in.null
when its pending.null
when its pending log.blockNumber
:Number
- the block number where this log was in.null
when its pending.null
when its pending log.address
:String
, 32 Bytes - address from which this log originated.data
:String
- contains one or more 32 Bytes non-indexed arguments of the log.topics
:Array of Strings
- Array of 0 to 4 32 BytesDATA
of indexed log arguments. (In solidity: The first topic is the hash of the signature of the event (e.g.Deposit(address,bytes32,uint256)
), except if you declared the event with theanonymous
specifier.)type
:STRING
-pending
when the log is pending.mined
if log is already mined. Note For event filter return values see Contract Events
Example
web3.pi.contract
Creates a contract object for a solidity contract, which can be used to initiate contracts on an address. You can read more about events here.
Parameters
Array
- ABI array with descriptions of functions and events of the contract.
Returns
Object
- A contract object, which can be initiated as follows:
And then you can either initiate an existing contract on an address, or deploy the contract using the compiled byte code:
Example
Contract Methods
The contract object exposes the contract's methods, which can be called using parameters and a transaction object.
Parameters
String|Number|BigNumber
- (optional) Zero or more parameters of the function. If passing in a string, it must be formatted as a hex number, e.g. "0xdeadbeef" If you have already created BigNumber object, then you can just pass it too.Object
- (optional) The (previous) last parameter can be a transaction object, see web3.pi.sendTransaction parameter 1 for more. Note:data
andto
properties will not be taken into account.Number|String
- (optional) If you pass this parameter it will not use the default block set with web3.pi.defaultBlock.Function
- (optional) If you pass a callback as the last parameter the HTTP request is made asynchronous. See this note for details.
Returns
String
- If its a call the result data, if its a send transaction a created contract address, or the transaction hash, see web3.pi.sendTransaction for details.
Example
Contract Events
You can use events like filters and they have the same methods, but you pass different objects to create the event filter.
Parameters
Object
- Indexed return values you want to filter the logs by, e.g.{'valueA': 1, 'valueB': [myFirstAddress, mySecondAddress]}
. By default all filter values are set tonull
. It means, that they will match any event of given type sent from this contract.Object
- Additional filter options, see filters parameter 1 for more. By default filterObject has field 'address' set to address of the contract. Also first topic is the signature of event.Function
- (optional) If you pass a callback as the last parameter it will immediately start watching and you don't need to callmyEvent.watch(function(){})
. See this note for details.
Callback return
Object
- An event object as follows:
address
:String
, 32 Bytes - address from which this log originated.args
:Object
- The arguments coming from the event.blockHash
:String
, 32 Bytes - hash of the block where this log was in.null
when its pending.blockNumber
:Number
- the block number where this log was in.null
when its pending.logIndex
:Number
- integer of the log index position in the block.event
:String
- The event name.removed
:bool
- indicate if the transaction this event was created from was removed from the blockchain (due to orphaned block) or never get to it (due to rejected transaction).transactionIndex
:Number
- integer of the transactions index position log was created from.transactionHash
:String
, 32 Bytes - hash of the transactions this log was created from.
Example
Contract allEvents
Will call the callback for all events which are created by this contract.
Parameters
Object
- Additional filter options, see filters parameter 1 for more. By default filterObject has field 'address' set to address of the contract. This method sets the topic to the signature of event, and does not support additional topics.Function
- (optional) If you pass a callback as the last parameter it will immediately start watching and you don't need to callmyEvent.watch(function(){})
. See this note for details.
Callback return
Object
- See Contract Events for more.
Example
web3.pi.getCompilers
Compiling features being deprecated https://github.com/pchain/EIPs/issues/209
Gets a list of available compilers.
Parameters
Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Array
- An array of strings of available compilers.
Example
web3.pi.compile.solidity
Compiles solidity source code.
Parameters
String
- The solidity source code.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Object
- Contract and compiler info.
Example
web3.pi.compile.lll
Compiles LLL source code.
Parameters
String
- The LLL source code.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The compiled LLL code as HEX string.
Example
web3.pi.compile.serpent
Compiles serpent source code.
Parameters
String
- The serpent source code.Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
String
- The compiled serpent code as HEX string.
web3.pi.namereg
Returns GlobalRegistrar object.
Usage
see namereg example.
web3.db.putString
This method should be called, when we want to store a string in the local leveldb database.
Parameters
String
- The database to store to.String
- The name of the store.String
- The string value to store.
Returns
Boolean
- true
if successfull, otherwise false
.
Example
param is db name, second is the key, and third is the string value.
web3.db.getString
This method should be called, when we want to get string from the local leveldb database.
Parameters
String
- The database string name to retrieve from.String
- The name of the store.
Returns
String
- The stored value.
Example
param is db name and second is the key of string value.
web3.db.putHex
This method should be called, when we want to store binary data in HEX form in the local leveldb database.
Parameters
String
- The database to store to.String
- The name of the store.String
- The HEX string to store.
Returns
Boolean
- true
if successfull, otherwise false
.
Example
web3.db.getHex
This method should be called, when we want to get a binary data in HEX form from the local leveldb database.
Parameters
String
- The database to store to.String
- The name of the store.
Returns
String
- The stored HEX value.
Example
param is db name and second is the key of value.
web3.shh
The web3-shh package allows you to interact with the whisper protocol for broadcasting. For more see Whisper Overview.
Example
web3.shh.addPrivateKey
Stores a key pair derived from a private key, and returns its ID.
Parameters
String - The private key as HEX bytes to import.
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - The Key ID on success and an error on failure.
Example
web3.shh.addSymKey
Stores the key, and returns its ID.
Parameters
String - The raw key for symmetric encryption as HEX bytes.
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns the key ID on success and an error on failure.
Example
web3.shh.deleteKeyPair
Parameters
String - The key pair ID, returned by the creation functions (shh.newKeyPair and shh.addPrivateKey).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns true on success, error on failure.
Example
web3.shh.deleteSymKey
Deletes the symmetric key associated with the given ID.
Parameters
String - The key pair ID, returned by the creation functions (shh.newKeyPair and shh.addPrivateKey).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns true on success, error on failure.
Example
web3.shh.generateSymKeyFromPassword
Generates the key from password, stores it, and returns its ID.
Parameters
String - A password to generate the sym key from.
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise<String|Error> - Returns the Key ID on success and an error on failure.
Example
web3.shh.getPrivateKey
Returns the private key for a key pair ID.
Parameters
String - The key pair ID, returned by the creation functions (shh.newKeyPair and shh.addPrivateKey).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns the private key on success and an error on failure.
Example
web3.shh.getPublicKey
Returns the public key for a key pair ID.
Parameters
String - The key pair ID, returned by the creation functions (shh.newKeyPair and shh.addPrivateKey).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns the Public key on success and an error on failure.
Example
web3.shh.getSymKey
Returns the symmetric key associated with the given ID.
Parameters
String - The key pair ID, returned by the creation functions (shh.newKeyPair and shh.addPrivateKey).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns the raw symmetric key on success and an error on failure.
Example
web3.shh.hasKeyPair
Checks if the whisper node has a private key of a key pair matching the given ID.
Parameters
String - The key pair ID, returned by the creation functions (shh.newKeyPair and shh.addPrivateKey).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns true on if the key pair exist in the node, false if not. Error on failure.
Example
web3.shh.hasSymKey
Checks if there is a symmetric key stored with the given ID.
Parameters
String - The key pair ID, returned by the creation functions (shh.newSymKey, shh.addSymKey or shh.generateSymKeyFromPassword).
Function - (optional) Optional callback, returns an error object as first parameter and the result as second.
Returns
Promise - Returns true on if the symmetric key exist in the node, false if not. Error on failure.
Example
web3.shh.post
This method should be called, when we want to post whisper message to the network.
Parameters
Object
- The post object:
from
:String
, 60 Bytes HEX - (optional) The identity of the sender.to
:String
, 60 Bytes HEX - (optional) The identity of the receiver. When present whisper will encrypt the message so that only the receiver can decrypt it.topics
:Array of Strings
- Array of topicsStrings
, for the receiver to identify messages.payload
:String|Number|Object
- The payload of the message. Will be autoconverted to a HEX string before.priority
:Number
- The integer of the priority in a range from ... (?).ttl
:Number
- integer of the time to live in seconds.
Function
- (optional) If you pass a callback the HTTP request is made asynchronous. See this note for details.
Returns
Boolean
- returns true
if the message was sent, otherwise false
.
Example
web3.pi.sendIBANTransaction
Sends IBAN transaction from user account to destination IBAN address.
Parameters
string
- address from which we want to send transactionstring
- IBAN address to which we want to send transactionvalue
- value that we want to send in IBAN transaction
web3.pi.iban
web3.pi.iban.toAddress
web3.pi.iban.toIban
web3.pi.iban.fromAddress
web3.pi.iban.fromBban
web3.pi.iban.createIndirect
web3.pi.iban.isValid
web3.pi.iban.isDirect
web3.pi.iban.isIndirect
web3.pi.iban.checksum
web3.pi.iban.institution
web3.pi.iban.client
web3.pi.iban.address
web3.pi.iban.toString
web3.chain.createChildChain
Send an application of subchain Creation, save the application into the ChainInfo DB
Parameters
from
, address - the address who triggers the actionchainId
, string - subchain idminValidators
, hex string - Minimum Validators of the new subchainminDepositAmount
, hex string - Minimum Deposit PAI of the new subchainstartBlock
, hex string - Start Block height for launch subchainendBlock
, hex string - End Block height for launch subchaingasPrice
, hex string - ( if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.chain.joinChildChain
Send a request to Join the subchain, save the Join Application into the ChainInfo DB, after the blockchain match the criteria of the subchain, chainMgr will load the subchain Data from ChainInfo DB then start it
Parameters
from
: address, 20 Bytes - the address who triggers the actionpubkey
: hex string, 128 Bytes - the BLS Public Key who triggers the actionchainId
: string - subchain iddepositAmount
: hex string - Amount of the Deposit PAI to join the subchainsignature
: hex string, 64 Bytes - the signature of From Address, signed by BLS Private Key. (How to sign, see web3.chain.signAddress)gasPrice
: hex string - ( if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.chain.depositInMainChain
Send a request to Join the subchain, save the Join Application into the ChainInfo DB, after the blockchain match the criteria of the subchain, chainMgr will load the subchain Data from ChainInfo DB then start it
Parameters
from
, address - the address who triggers the actionchainId
, string - subchain idamount
, hex string - amount of PAI to depositgasPrice
, hex string - ( if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.chain.depositInChildChain
Deposit from the main chain to subchain (step 2). Should be used with chain_depositInMainChain
Parameters
from
, address - the address who triggers the actiontxHash
, string - Tx Hash of the chain_depositInMainChain rpc
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.chain.withdrawFromChildChain
Withdraw from subchain to the main chain (step 1). Should be used with chain_withdrawFromMainChain
Parameters
from
, address - the address who triggers the actionamount
, hex string - amount of PAI to withdrawgasPrice
, hex string - gas price from the request
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.chain.withdrawFromMainChain
Withdraw from subchain to the main chain (step 2). Should be used with chain_withdrawFromChildChain
Parameters
from
, address - the address who triggers the actionamount
, hex string - amount of PAI to withdrawchainId
, string - subchain idtxHash
, string - Tx Hash of the chain_withdrawFromChildChain rpc
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.chain.signAddress
Sign the Address with BLS Private Key, return the BLS Signature to proof you are the owner of the BLS Public Key
Parameters
from
: address, 20 Bytes - Address which will be signedprivateKey
: hex string, 32 Bytes - BLS Private Key,How To Get Your Privatekey
Returns
DATA
, 64 Bytes - the BLS Signature for the Address
Example
web3.chain.setBlockReward
Set the Reward of each block for the subchain, only subchain Owner is allowed to send this tx. The Block Reward change will effect on the next block after this tx be mined.
The Block Reward will be charged from subchain Address 0x0000000000000000000000000000000000000064 balance, which accept anyone to transfer their contribution
Parameters
from
: address, 20 Bytes - Owner Address of subchainreward
: hex string - The reward of each block
Returns
hash
, string - the transaction hash
Example
web3.chain.getBlockReward
Get the Reward of each block for the subchain
Parameters
QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
Returns
QUANTITY
- integer of the block reward in wei
Example
web3.chain.getAllChains
Get all the Chain Info from the node (A synced Full node should have all the chains' info)
Parameters
none
Returns
Object
- The chain info object
chain_id
:String
- The chain id of the chain.owner
:Address
, 20 Bytes - The owner address of the chain.current_epoch
:Number
- The current epoch number of the chain.epoch_start_time
:Time
- The start time of the current epochvalidators
:Array
- Array of validator objectaddress
:Address
- Address of the Validator
voting_power
:QUANTITY
- Voting Power (Stack) of the Validator
Example
web3.tdm.voteNextEpoch
Send hash of Vote for the next epoch
Parameters
from
: address, 20 Bytes - the address who triggers the actionvoteHash
: hex string, 32 Bytes - hash of the vote. (How to get the vote hash, use Keccak-256 (not the standardized SHA3-256) example: keccak256(from + pubkey + amount + salt) ),see web3.getVoteHashgasPrice
: hex string - (if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.tdm.revealVote
Reveal the vote, the content of vote should matched with the hash which provided in tdm_voteNextEpoch
Parameters
from
: address, 20 Bytes - the address who triggers the actionpubkey
: hex string, 128 Bytes - the BLS Public Key who triggers the actionamount
: hex string - the amount of votesalt
: string - salt stringsignature
: hex string, 64 Bytes - the signature of From Address, signed by BLS Private Key. (How to sign, see chain_signAddress)gasPrice
: hex string - (if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
String
- The 32 Bytes transaction hash as HEX string.
Example
web3.tdm.getCurrentEpochNumber
Returns the current epoch number
Parameters
none
Returns
epochNumber
, int - current epoch number
Example
web3.tdm.getEpoch
Returns the epoch details
Parameters
number
, int - epoch number
Returns
the epoch details
Example
web3.tdm.getNextEpochVote
Returns the votes details of the next epoch
Parameters
none
Returns
result
, string - votes detail of the next epoch, such as epoch number, start block, end block, votes
Example
web3.tdm.getNextEpochValidators
Returns the validators of the next epoch based on the votes
Parameters
none
Returns
result
, DATA - validators of the next epoch, such as address, public key, voting power
Example
web3.tdm.generatePrivateValidator
Returns the generated BLS Public/Private Key associate with provided address
Parameters
from
: address, 20 Bytes - the address
Returns
address
: address, 20 Bytes - address from the requestconsensus_pub_key
: hex string, 128 Bytes - the generated BLS Public Keyconsensus_priv_key
: hex string, 32 Bytes - the generated BLS Private Key
Example
web3.del.delegate
Create a new transaction to Delegate your balance to Candidate
Parameters
from
: address, 20 Bytes - the address who triggers the actioncandidate
: address, 20 Bytes - the address of candidateamount
: hex string - Amount of the Delegate PAIgasPrice
: hex string - (if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
hash
, hex string - the transaction hash
Example
web3.del.cancelDelegate
Create a new transaction to Cancel your Delegation from Candidate
Parameters
from
: address, 20 Bytes - the address who triggers the actioncandidate
: address, 20 Bytes - the address of candidateamount
: hex string - Amount of the Delegate PAIgasPrice
: hex string - (if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
hash
, hex string - the transaction hash
Example
web3.del.applyCandidate
Create a new transaction to become a Candidate (with specific security deposit and commission fee rate)
Parameters
from
: address, 20 Bytes - the address who triggers the actionsecurityDeposit
: hex string - Amount of the security deposit PAI (minimum 10,000 PAI)commission
: integer - the commission fee percentage of each Block Reward be charged to proxied de, when Candidate become a Validator (between 0 - 100)gasPrice
: hex string - (if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
hash
, hex string - the transaction hash
Example
web3.del.cancelCandidate
Create a new transaction to become a Candidate (with specific security deposit and commission fee rate)
Parameters
from
: address, 20 Bytes - the address who triggers the actiongasPrice
: hex string - (if set to null,system will give default value(1 gwei) ) gas price from the request
Returns
hash
, hex string - the transaction hash
Example
web3.del.checkCandidate
CReturns the candidate status of the account of given address.
Parameters
from
: address, 20 Bytes - the address who triggers the actionblockNumber
: QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending"
Returns
candidate
: Boolean - Candidate Flag of the given addresscommission
: QUANTITY - commission percentage of Candidate Address
Example
Last updated