This is the main class that interact with IOST blockchain and IOST smart contracts to get informations from them.
constructor
constructor method is a special method for creating and initializing Blockchain class.
DO NOT need to initialize by user, user will use Blockchain class by rpc.blockchain。
getChainInfo
get chain info from blockchain
Returns
Promise returns chainInfo object.
| Name | Type | Description |
|---|
| net_name | String | the name of network, such mainnet or testnet |
| protocol_version | String | the iost protocol version |
| head_block | Number | head block height |
| head_block_hash | String | head block hash |
| lib_block | Number | last irreversible block number |
| lib_block_hash | String | last irreversible block hash |
| witness_list | Array | the current witness list |
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getChainInfo().then(console.log);
getBlockByHash
get block info from blockchain by hash
Parameters
| Name | Type | Description |
|---|
| hash | String | the hash of the block |
| complete | Boolean | complete means whether including the full transactions and transaction receipts |
Returns
Promise returns block object.
| Name | Type | Description |
|---|
| status | String | transaction status |
| block | Object | Block Object |
Block Object
| Name | Type | Description |
|---|
| hash | String | block hash |
| version | Number | block version |
| parent_hash | String | parent block hash |
| tx_merkle_hash | String | transaction merkle tree root hash |
| tx_receipt_merkle_hash | String | transaction receipt merkle tree root hash |
| number | String | block number |
| witness | String | block producer witness |
| time | String | block timestamp |
| gas_usage | String | block gas usage |
| tx_count | String | transaction count |
| transactions | Array | array of Transaction Object |
| info | Object | Info Object |
AmountLimit Object
| Name | Type | Description |
|---|
| token | String | token name |
| value | Number | limit value |
Info Object
| Name | Type | Description |
|---|
| mode | Number | pack mode |
| thread | Number | transaction execution thread number |
| batch_index | Array | transaction index of every batch execution |
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getBlockByNum(1, true).then(console.log);
getBlockByNum
get block info from blockchain by num
Parameters
| Name | Type | Description |
|---|
| num | Number | the number of the block |
| complete | Boolean | complete means whether including the full transactions and transaction receipts |
Returns
Promise returns block object. check getBlockByHash
getBalance
get account balance
Parameters
| Name | Type | Description |
|---|
| name | String | account name |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns balance object.
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getBalance('myaccount', true).then(console.log);
getToken721Balance
get account token721 balance
Parameters
| Name | Type | Description |
|---|
| name | String | account name |
| tokenSymbol | String | token721 symbol |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns balance object.
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getToken721Balance('myaccount', 'my721Token', true).then(console.log);
get token721 metadata
Parameters
| Name | Type | Description |
|---|
| token | String | token name |
| token_id | String | token id |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns metadata object.
| Name | Type | Description |
|---|
| metadata | String | metadata |
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getToken721Metadata('symbol', 'id', true).then(console.log);
getToken721Owner
get token721 owner
Parameters
| Name | Type | Description |
|---|
| token | String | token name |
| token_id | String | token id |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns owner object.
| Name | Type | Description |
|---|
| owner | String | metadata |
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getToken721Owner('symbol', 'id', true).then(console.log);
getContract
get contract from blockchain
Parameters
| Name | Type | Description |
|---|
| id | String | contract id |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns contract object.
| Name | Type | Description |
|---|
| id | String | contract id |
| code | String | contract code |
| language | String | contract language |
| version | String | contract version |
| abis | Array | array of ABI Object |
ABI Object
| Name | Type | Description |
|---|
| name | String | contract id |
| args | Array | abi arguments |
| amount_limit | Array | array of AmountLimit Object |
getContractStorage
get contract storage from blockchain
Parameters
| Name | Type | Description |
|---|
| id | String | contract id |
| key | String | the key in the StateDB |
| field | String | get the value from StateDB, field is needed if StateDB[key] is a map.(we get StateDB[key][field] in this case) |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns contract result object.
| Name | Type | Description |
|---|
| data | String | data |
getAccountInfo
get account info from blockchain
Parameters
| Name | Type | Description |
|---|
| name | String | account name |
| by_longest_chain | Boolean | get account by longest chain's head block or last irreversible block |
Returns
Promise returns account object.
GasInfo Object
| Name | Type | Description |
|---|
| current_total | Number | current total gas amount |
| transferable_gas | Number | current transferable gas |
| pledge_gas | Number | current pledge gas |
| increase_speed | Number | gas increase speed |
| limit | Number | account name |
| pledged_info | Array | array of PledgeInfo Object |
PledgeInfo Object
| Name | Type | Description |
|---|
| pledger | String | the account who pledges |
| amount | Number | pledged amount |
RAMInfo Object
| Name | Type | Description |
|---|
| available | Number | available ram bytes |
Permission Object
| Name | Type | Description |
|---|
| name | String | permission name |
| groups | Array | array of permission groups |
| items | Array | array of Item Object |
| threshold | Number | permission threshold |
Item Object
| Name | Type | Description |
|---|
| id | String | permission name or key pair id |
| is_key_pair | Boolen | whether it's a key pair |
| weight | Number | permission weight |
| permission | String | permission |
Group Object
| Name | Type | Description |
|---|
| name | String | group name |
| items | Array | array of Item Object |
FrozenBalance Object
| Name | Type | Description |
|---|
| amount | Number | balance amount |
| time | Number | free time |
Example
const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getAccountInfo("myaccount").then(console.log);