Get a Block
You can retrieve a block's data by calling the Client.get_block(&block_id)
function.
You can also retrieve a block's metadata by calling the Client.get_block_metadata(&block_id)
function.
The following code example will:
- Create a
Client
which will connect to the Shimmer Testnet. - Create a block with no payload.
- Retrieve and log the block's metadata.
- Retrieve and log the block's data.
- Get the block by its block ID.
Iota.js
You can also find this guide in the native iota.js library
Code Example
- Rust
- Nodejs
- Python
- Java
Dotenv
This example uses dotenv, which is not safe to use in production environments.
client/examples/node_api_core/06_get_block.rs
loading...
Run the Example
Run the example by running the following command:
cargo run --example node_api_core_get_block --release -- https://api.testnet.shimmer.network 0xa9f11aba1e9965173dc21a47ec4fbfe5b953a6e60277857a3f7a5c1499e7c454
- You can replace
https://api.testnet.shimmer.network
with any node url. - You can replace
0x78680faa5ee34d77399ad7eff5fec9b9ceb99fea86822a16f57f49aa69771ee5
with any other Block ID.
Dotenv
This example uses dotenv, which is not safe to use in production environments.
client/bindings/nodejs/examples/07_get_block_data.ts
loading...
You can run the example by running the following command from the bindings/node/examples/
folder:
node dist/07_get_block_data.js
client/bindings/python/examples/07_get_block_data.py
loading...
You can run the example by running the following command from the binding/python/examples
folder:
python3 07_get_block_data.py
client/bindings/java/examples/src/GetBlock.java
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Block {
protocol_version: 2,
parents: Parents(
BoxedSlicePrefix([
BlockId(0x2ec007718ebd1f8dd10be36c76820321fd24fd1739a52a7176f3314f1158ea44),
BlockId(0x536f8b2beba143278bda5074a311c827ef37c5756d80ea90372b2688b92cd5ae),
BlockId(0x6b6bcad97ba4f8d6f75aeea1dfc945425d2d6ead793af302dd5040590f5e409d),
BlockId(0xcff2436f2d65438c7351946fe793af3a8f059b485250d0ee2c5875d0aed71884),
]),
),
payload: OptionalPayload(
Some(
Transaction(
TransactionPayload {
essence: Regular(
RegularTransactionEssence {
network_id: 1856588631910923207,
inputs: BoxedSlicePrefix([
Utxo(
UtxoInput(0xcb664cb88dcb4182df622fb82661e2d82e81ff95f3f04d5f3b071484a10fdc490100),
),
Utxo(
UtxoInput(0xeede6413d25f1cb1fc68187cda339ec22e66e4fb945b8397c7251d46164a0c495900),
),
Utxo(
UtxoInput(0x45a6247d6af3214828fcab1206f6b6c8e61a359fec821d48cb578b3f70a291a40000),
),
Utxo(
UtxoInput(0x71638c38cf0be640f082edf9b1a9dc1ea898932762ede49b164f0894826009703b00),
),
]),
inputs_commitment: InputsCommitment(0x10cb15a61c30e10e569f10513834d5fd0ee53049a77223ccf43a921ea22e1675),
outputs: BoxedSlicePrefix([
Alias(
AliasOutput {
amount: BoundedU64(
53700,
),
native_tokens: NativeTokens(
BoxedSlicePrefix([]),
),
alias_id: AliasId(0x0000000000000000000000000000000000000000000000000000000000000000),
state_index: 0,
state_metadata: BoxedSlicePrefix([]),
foundry_counter: 0,
unlock_conditions: UnlockConditions(
BoxedSlicePrefix([
StateControllerAddress(
StateControllerAddressUnlockCondition(
Ed25519(
Ed25519Address(0x4f56285a1876d31b62f085c1bb35a85c0edc29889074631b81172991c3e4d6ff),
),
),
),
GovernorAddress(
GovernorAddressUnlockCondition(
Ed25519(
Ed25519Address(0x4f56285a1876d31b62f085c1bb35a85c0edc29889074631b81172991c3e4d6ff),
),
),
),
]),
),
features: Features(
BoxedSlicePrefix([]),
),
immutable_features: Features(
BoxedSlicePrefix([
Issuer(
IssuerFeature(
Ed25519(
Ed25519Address(0x4f56285a1876d31b62f085c1bb35a85c0edc29889074631b81172991c3e4d6ff),
),
),
),
]),
),
},
),
Basic(
BasicOutput {
amount: BoundedU64(
1000047500,
),
native_tokens: NativeTokens(
BoxedSlicePrefix([]),
),
unlock_conditions: UnlockConditions(
BoxedSlicePrefix([
Address(
AddressUnlockCondition(
Ed25519(
Ed25519Address(0x4f56285a1876d31b62f085c1bb35a85c0edc29889074631b81172991c3e4d6ff),
),
),
),
]),
),
features: Features(
BoxedSlicePrefix([]),
),
},
),
]),
payload: OptionalPayload(
Some(
TaggedData(
TaggedDataPayload {
tag: "0x484f524e4554205370616d6d65722053656d692d4c617a79",
data: "0x57652061726520616c6c206d616465206f662073746172647573742e0a436f756e743a203030353539320a54696d657374616d703a20323032322d30392d30315431343a32323a33345a0a54697073656c656374696f6e3a2031312e3832376d73",
},
),
),
),
},
),
unlocks: Unlocks(
BoxedSlicePrefix([
Signature(
SignatureUnlock(
Ed25519(
Ed25519Signature {
public_key: 0x229172a3883abbeb5ff7e680a6a0a0f5c31bf222d48fd1747d9d0ead24155a6b,
signature: 0x354174e8f7981aa05eca6d936cd2c7bf0eb9e2954b1f550e683959eb412194f8edab0f8536c370e576eb812da434496749221c3b96b40d6d2c9de4c06d97030f,
},
),
),
),
Reference(
ReferenceUnlock(
BoundedU16(
0,
),
),
),
Reference(
ReferenceUnlock(
BoundedU16(
0,
),
),
),
Reference(
ReferenceUnlock(
BoundedU16(
0,
),
),
),
]),
),
},
),
),
),
nonce: 1785168781326821022,
}
Block: [
'0xb6133638cb4653f3d00585e114dc64db22ed2c9402f03ca5e7894e236673662e',
{
protocolVersion: 2,
parents: [
'0x03191e7d2cea9b2a9c0dc0ff4d43bfd3f95aad7c7d45d7ebd9f7825f0a108c26',
'0x7e914209c791fe529bcae19870c21b1ceab8b0e529ef884797395ae73d90c318',
'0xdbc196d4e46d0fb9c3a7aba24213840e09b107c1c7510974b19b83ef4ab93b75',
'0xfcae9899666214e0c831e63caaec4030d83380fd2d7194a2ae23abecfd987dc2'
],
nonce: '1537228672809154665'
}
]
Block metadata: {
blockId: '0xb6133638cb4653f3d00585e114dc64db22ed2c9402f03ca5e7894e236673662e',
parents: [
'0x03191e7d2cea9b2a9c0dc0ff4d43bfd3f95aad7c7d45d7ebd9f7825f0a108c26',
'0x7e914209c791fe529bcae19870c21b1ceab8b0e529ef884797395ae73d90c318',
'0xdbc196d4e46d0fb9c3a7aba24213840e09b107c1c7510974b19b83ef4ab93b75',
'0xfcae9899666214e0c831e63caaec4030d83380fd2d7194a2ae23abecfd987dc2'
],
isSolid: true,
shouldPromote: false,
shouldReattach: false
}
Block data: {
protocolVersion: 2,
parents: [
'0x03191e7d2cea9b2a9c0dc0ff4d43bfd3f95aad7c7d45d7ebd9f7825f0a108c26',
'0x7e914209c791fe529bcae19870c21b1ceab8b0e529ef884797395ae73d90c318',
'0xdbc196d4e46d0fb9c3a7aba24213840e09b107c1c7510974b19b83ef4ab93b75',
'0xfcae9899666214e0c831e63caaec4030d83380fd2d7194a2ae23abecfd987dc2'
],
nonce: '1537228672809154665'
}
[
'0xd1cb2c76a7ebbab78336dc185e565920aa165590e9f8a1f4b94d9dc381f24a81',
{
'protocolVersion': 2,
'parents': [
'0x2cb6a30010b7b108262504545f2ff23da9c2fe7bf7e09f200140dd4edebcd0c9',
'0x4c145b3e311ea1a37b1601efb80f19ca3e3ee431dad9aeebfa18976b67646fac',
'0x5de1ab132cf00d590ca4bfd8f8c06fc576ac9dbd56d1fa4be5720f8583978533',
'0xc4838f69b7f5f7d4860341bd7483d19d814ce6df8dc60b72245d94d938970404'
],
'nonce': '13835058055282164293'
}
]
{
'blockId': '0xd1cb2c76a7ebbab78336dc185e565920aa165590e9f8a1f4b94d9dc381f24a81',
'parents': [
'0x2cb6a30010b7b108262504545f2ff23da9c2fe7bf7e09f200140dd4edebcd0c9',
'0x4c145b3e311ea1a37b1601efb80f19ca3e3ee431dad9aeebfa18976b67646fac',
'0x5de1ab132cf00d590ca4bfd8f8c06fc576ac9dbd56d1fa4be5720f8583978533',
'0xc4838f69b7f5f7d4860341bd7483d19d814ce6df8dc60b72245d94d938970404'
],
'isSolid': True,
'shouldPromote': False,
'shouldReattach': False
}
{
'protocolVersion': 2,
'parents': [
'0x2cb6a30010b7b108262504545f2ff23da9c2fe7bf7e09f200140dd4edebcd0c9',
'0x4c145b3e311ea1a37b1601efb80f19ca3e3ee431dad9aeebfa18976b67646fac',
'0x5de1ab132cf00d590ca4bfd8f8c06fc576ac9dbd56d1fa4be5720f8583978533',
'0xc4838f69b7f5f7d4860341bd7483d19d814ce6df8dc60b72245d94d938970404'
],
'nonce': '13835058055282164293'
}
{
"protocolVersion": 2,
"parents": [
"0x452105dc88c4c4c927dcf9b3658a99d82331583cc84e84caf58669f0fcce4588",
"0xb8d06ee5dfcf512cc782facaaf54eaac77942ff529f69b8d129fb4009b38f68f",
"0xbd2792748becac463beba3e1ad952453dd225edd6d68ddd91bb41f9a88eb5a3e",
"0xbf22b0a595927f5c44f1991662f5c0a3702f38a851c0a37dd58f8977cda102d8"
],
"payload": {
"type": 5,
"tag": "0x484f524e4554205370616d6d6572",
"data": "0x57652061726520616c6c206d616465206f662073746172647573742e0a436f756e743a20313332343432300a54696d657374616d703a20323032322d30392d30315431343a32393a32345a0a54697073656c656374696f6e3a20343032c2b573"
},
"nonce": "341022"
}