メインコンテンツまでスキップ
バージョン: 3.4.0

Blockchain

Blockchainクラスは、IOSTブロックチェーンを使ったり、情報を取得したりするためのクラスです。

constructor

constructorメソッドは、特殊なメソッドで、Blockchainクラスを作成し、初期化します。 ユーザが初期化する必要はありません。ユーザはrpc.blockchainでBlockchainクラスを使えます。

getChainInfo

ブロックチェーンからチェーン情報を取得します。

戻り値

chainInfoオブジェクトを返すPromise。

名前説明
net_nameStringネットワーク名、mainnetまたはtestnet
protocol_versionStringIOSTプロトコルのバージョン
head_blockNumber先頭ブロック高
head_block_hashString先頭ブロックハッシュ
lib_blockNumber最終不可逆ブロック番号
lib_block_hashString最終不可逆ブロックハッシュ
witness_listArray現在の目撃者リスト

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

ハッシュにより、ブロックチェーンからブロック情報を取得します。

パラメータ

名前説明
hashStringブロックハッシュ
completeBoolean完全なトランザクションとトランザクションレシートを持っていればtrue

戻り値

ブロックオブジェクトを返すPromise。

名前説明
statusStringトランザクションのステータス
blockObjectBlockオブジェクト

Blockオブジェクト

名前説明
hashStringブロックハッシュ
versionNumberブロックのバージョン
parent_hashString親のブロックハッシュ
tx_merkle_hashStringトランザクションのマークルツリールートハッシュ
tx_receipt_merkle_hashStringトランザクションレシートのマークルツリールートハッシュ
numberStringブロック番号
witnessStringブロックプロデューサー
timeStringブロックのタイムスタンプ
gas_usageStringブロックのGAS使用量
tx_countStringトランザクション数
transactionsArrayTransactionオブジェクトの配列
infoObjectInfoオブジェクト

AmountLimitオブジェクト

名前説明
tokenStringトークン名 name
valueNumber制限値

Infoオブジェクト

名前説明
modeNumberパックモード
threadNumberトランザクション実行中スレッド番号
batch_indexArray各バッチ実行のトランザクションインデックス

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

番号でブロックチェーンからブロックを取得します。

パラメータ

名前説明
numNumberブロック番号
completeBoolean完全なトランザクションとトランザクションレシートを持っていればtrue

戻り値

ブロックオブジェクトを返すPromise。 getBlockByHashをチェックしてください。

getBalance

残高を取得します。

パラメータ

名前説明
nameStringアカウント名
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

残高オブジェクトを返すPromise。

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

アカウントのtoken721残高を取得します。

パラメータ

名前説明
nameStringアカウント名
tokenSymbolStringtoken721 シンボル
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

残高オブジェクトを返すPromise。

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

token721のメタデータを取得します。

パラメータ

名前説明
tokenStringトークン名
token_idStringトークンID
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

メタデータを返すPromise。

名前説明
metadataStringメタデータ

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

token721のオーナーを取得します。

パラメータ

名前説明
tokenStringトークン名 token_id
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

オーナーオブジェクトを返すPromise。

名前説明
ownerStringメタデータ

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

ブロックチェーンからコントラクトを取得します。

パラメータ

名前説明
idStringコントラクトID
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

コントラクトオブジェクトを返すPromise。

名前説明
idStringコントラクトID
codeStringコントラクトコード
languageStringコントラクト使用言語
versionStringコントラクトのバージョン
abisArrayABIオブジェクトの配列

ABIオブジェクト

名前説明
nameStringコントラクトID
argsArrayABI引数
amount_limitArray AmountLimitオブジェクトの配列

getContractStorage

ブロックチェーンからコントラクトのストレージを取得します。

パラメータ

名前説明
idStringコントラクトID
keyStringStateDBのキー
fieldStringStateDBからの値で、StateDB[key]がマップなら、fieldは必須(この場合、StateDB[key][field]を取得)
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

コントラクトの結果オブジェクトを返すPromise。

名前説明
dataStringデータ

getAccountInfo

ブロックチェーンからアカウント情報を取得します。

パラメータ

名前説明
anmeStringアカウント名
by_longest_chainBoolean最長のチェーンの先頭ブロック、または最終不可逆ブロックによるアカウントか

戻り値

アカウント情報を返すPromise。

名前説明
nameStringアカウント名¥
balanceNumberアカウントの残高
gas_infoObjectGasInfoオブジェクト
ram_infoObjectRAMInfoオブジェクト
permissionsMapmap<String, Permissionオブジェクト>
groupsMapmap<String, Groupオブジェクト>
frozen_balancesArrayFrozenBalanceオブジェクトの配列

GasInfoオブジェクト

名前説明
current_totalNumber現在の総GAS量
transferable_gasNumber現在の転送可能GAS
pledge_gasNumber出資GAS
increase_speedNumberGAS増加速度
limitNumber制限
pledged_infoArrayPledgeInfoオブジェクトの配列

PledgeInfoオブジェクト

名前説明
pledgerString出資者
amountNumber出資する量

RAMInfoオブジェクト

名前説明
availableNumber使用可能RAM量(バイト)

Permissionオブジェクト

名前説明
nameString権限名
groupsArray権限グループの配列
itemsArrayItemオブジェクトの配列
thresholdNumber権限のしきい値

Itemオブジェクト

名前説明
idString権限名またはキーペアID
is_key_pairBoolenキーペアIDか
weightNumber権限の重み
permissionString権限

Groupオブジェクト

名前説明
nameStringグループ名
itemsArrayItemオブジェクトの配列

FrozenBalanceオブジェクト

名前説明
amountNumber残高
timeNumber解放までの時間(free time)

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": []
}*/