본문으로 건너뛰기
버전: 3.3.2

Blockchain

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.

NameTypeDescription
net_nameStringthe name of network, such mainnet or testnet
protocol_versionStringthe iost protocol version
head_blockNumberhead block height
head_block_hashStringhead block hash
lib_blockNumberlast irreversible block number
lib_block_hashStringlast irreversible block hash
witness_listArraythe current witness list

Example​

const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getChainInfo().then(console.log);

/*{
"net_name": "debugnet",
"protocol_version": "1.0",
"head_block": "142",
"head_block_hash": "ryj9qWvbypFd1VJeUiyxmyNiav9E8ZHH1t47zSbMmGk",
"lib_block": "142",
"lib_block_hash": "ryj9qWvbypFd1VJeUiyxmyNiav9E8ZHH1t47zSbMmGk",
"witness_list": [
"IOSTfQFocqDn7VrKV7vvPqhAQGyeFU9XMYo5SNn5yQbdbzC75wM7C"
]
}*/

getBlockByHash​

get block info from blockchain by hash

Parameters​

NameTypeDescription
hashStringthe hash of the block
completeBooleancomplete means whether including the full transactions and transaction receipts

Returns​

Promise returns block object.

NameTypeDescription
statusStringtransaction status
blockObjectBlock Object

Block Object​

NameTypeDescription
hashStringblock hash
versionNumberblock version
parent_hashStringparent block hash
tx_merkle_hashStringtransaction merkle tree root hash
tx_receipt_merkle_hashStringtransaction receipt merkle tree root hash
numberStringblock number
witnessStringblock producer witness
timeStringblock timestamp
gas_usageStringblock gas usage
tx_countStringtransaction count
transactionsArrayarray of Transaction Object
infoObjectInfo Object

AmountLimit Object​

NameTypeDescription
tokenStringtoken name
valueNumberlimit value

Info Object​

NameTypeDescription
modeNumberpack mode
threadNumbertransaction execution thread number
batch_indexArraytransaction 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);

/*{
"status": "IRREVERSIBLE",
"block": {
"hash": "HSSXypC9GwRowiG6e1FG9qGbvVZFjT9mR7RY8mGZzoLJ",
"version": "0",
"parent_hash": "CyoyPDfRM8a4HWwSbDBRv3UbFoUUQxWu4T5JuaJsmLvs",
"tx_merkle_hash": "7thvoWaULNdrXVYR6wRTfWYSpJDFj6vKX1jitCsh7KRj",
"tx_receipt_merkle_hash": "GvjAbjP9c626UPSMFjPMERyVDxqwvdu5uziqyiZdmoox",
"number": "1",
"witness": "IOSTfQFocqDn7VrKV7vvPqhAQGyeFU9XMYo5SNn5yQbdbzC75wM7C",
"time": "1545384717001253745",
"gas_usage": 0,
"tx_count": "1",
"info": null,
"transactions": [
{
"hash": "5YdA8qPq5N6W47rZV4u31FdbQzeMt2QX9KGj4uPyERZa",
"time": "0",
"expiration": "0",
"gas_ratio": 1,
"gas_limit": 1000000,
"delay": "0",
"actions": [
{
"contract": "base.iost",
"action_name": "Exec",
"data": "[{\"parent\":[\"IOST2FpDWNFqH9VuA8GbbVAwQcyYGHZxFeiTwSyaeyXnV84yJZAG7A\", \"0\"]}]"
}
],
"signers": [],
"publisher": "_Block_Base",
"referred_tx": "",
"amount_limit": [],
"tx_receipt": {
"tx_hash": "5YdA8qPq5N6W47rZV4u31FdbQzeMt2QX9KGj4uPyERZa",
"gas_usage": 0,
"ram_usage": {
"_Block_Base": "0",
"base.iost": "284",
"bonus.iost": "107"
},
"status_code": "SUCCESS",
"message": "",
"returns": [
"[\"\"]"
],
"receipts": [
{
"func_name": "token.iost/issue",
"content": "[\"contribute\",\"IOST2FpDWNFqH9VuA8GbbVAwQcyYGHZxFeiTwSyaeyXnV84yJZAG7A\",\"900\"]"
}
]
}
}
]
}
}*/

getBlockByNum​

get block info from blockchain by num

Parameters​

NameTypeDescription
numNumberthe number of the block
completeBooleancomplete means whether including the full transactions and transaction receipts

Returns​

Promise returns block object. check getBlockByHash

getBalance​

get account balance

Parameters​

NameTypeDescription
nameStringaccount name
by_longest_chainBooleanget 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);

/*{
balance: 12000,
frozen_balances: null
}*/

getToken721Balance​

get account token721 balance

Parameters​

NameTypeDescription
nameStringaccount name
tokenSymbolStringtoken721 symbol
by_longest_chainBooleanget 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);

/*{
balance: 12000,
tokenIDs: null
}*/

getToken721Metadata​

get token721 metadata

Parameters​

NameTypeDescription
tokenStringtoken name
token_idStringtoken id
by_longest_chainBooleanget account by longest chain's head block or last irreversible block

Returns​

Promise returns metadata object.

NameTypeDescription
metadataStringmetadata

Example​

const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getToken721Metadata('symbol', 'id', true).then(console.log);

/*{
metadata: ''
}*/

getToken721Owner​

get token721 owner

Parameters​

NameTypeDescription
tokenStringtoken name
token_idStringtoken id
by_longest_chainBooleanget account by longest chain's head block or last irreversible block

Returns​

Promise returns owner object.

NameTypeDescription
ownerStringmetadata

Example​

const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getToken721Owner('symbol', 'id', true).then(console.log);

/*{
owner: 'theowner'
}*/

getContract​

get contract from blockchain

Parameters​

NameTypeDescription
idStringcontract id
by_longest_chainBooleanget account by longest chain's head block or last irreversible block

Returns​

Promise returns contract object.

NameTypeDescription
idStringcontract id
codeStringcontract code
languageStringcontract language
versionStringcontract version
abisArrayarray of ABI Object

ABI Object​

NameTypeDescription
nameStringcontract id
argsArrayabi arguments
amount_limitArrayarray of AmountLimit Object

getContractStorage​

get contract storage from blockchain

Parameters​

NameTypeDescription
idStringcontract id
keyStringthe key in the StateDB
fieldStringget the value from StateDB, field is needed if StateDB[key] is a map.(we get StateDB[key][field] in this case)
by_longest_chainBooleanget account by longest chain's head block or last irreversible block

Returns​

Promise returns contract result object.

NameTypeDescription
dataStringdata

getAccountInfo​

get account info from blockchain

Parameters​

NameTypeDescription
nameStringaccount name
by_longest_chainBooleanget account by longest chain's head block or last irreversible block

Returns​

Promise returns account object.

NameTypeDescription
nameStringaccount name
balanceNumberaccount balance
gas_infoObjectGasInfo Object
ram_infoObjectRAMInfo Object
permissionsMapmap<String, Permission Object>
groupsMapmap<String, Group Object>
frozen_balancesArrayarray of FrozenBalance Object

GasInfo Object​

NameTypeDescription
current_totalNumbercurrent total gas amount
transferable_gasNumbercurrent transferable gas
pledge_gasNumbercurrent pledge gas
increase_speedNumbergas increase speed
limitNumberaccount name
pledged_infoArrayarray of PledgeInfo Object

PledgeInfo Object​

NameTypeDescription
pledgerStringthe account who pledges
amountNumberpledged amount

RAMInfo Object​

NameTypeDescription
availableNumberavailable ram bytes

Permission Object​

NameTypeDescription
nameStringpermission name
groupsArrayarray of permission groups
itemsArrayarray of Item Object
thresholdNumberpermission threshold

Item Object​

NameTypeDescription
idStringpermission name or key pair id
is_key_pairBoolenwhether it's a key pair
weightNumberpermission weight
permissionStringpermission

Group Object​

NameTypeDescription
nameStringgroup name
itemsArrayarray of Item Object

FrozenBalance Object​

NameTypeDescription
amountNumberbalance amount
timeNumberfree time

Example​

const rpc = new IOST.RPC(new IOST.HTTPProvider('http://127.0.0.1:30001'));
rpc.blockchain.getAccountInfo("myaccount").then(console.log);

/*{
"name": "myaccount",
"balance": 993939700,
"gas_info": {
"current_total": 3000000,
"transferable_gas": 0,
"pledge_gas": 3000000,
"increase_speed": 11,
"limit": 3000000,
"pledged_info": [
{
"pledger": "myaccount",
"amount": 100
}
]
},
"ram_info": {
"available": "100000"
},
"permissions": {
"active": {
"name": "active",
"groups": [],
"items": [
{
"id": "IOST2mCzj85xkSvMf1eoGtrexQcwE6gK8z5xr6Kc48DwxXPCqQJva4",
"is_key_pair": true,
"weight": "1",
"permission": ""
}
],
"threshold": "1"
},
"owner": {
"name": "owner",
"groups": [],
"items": [
{
"id": "IOST2mCzj85xkSvMf1eoGtrexQcwE6gK8z5xr6Kc48DwxXPCqQJva4",
"is_key_pair": true,
"weight": "1",
"permission": ""
}
],
"threshold": "1"
}
},
"groups": {},
"frozen_balances": []
}*/