Skip to main content

Create a Block

The simplest block you can create is an empty block. You will only need connect your client to a node and then call the Client.block(&self) function.

The following code example will:

  1. Create a Client which will connect to the Shimmer Testnet.
  2. Build and post an empty block.

Code Example

Dotenv

This example uses dotenv, which is not safe to use in production environments.

client/examples/block/00_block_no_payload.rs
loading...

Run the Example

Run the example by running the following command:

cargo run --example simple_block --release

Expected Output

Block {
protocol_version: 2,
parents: Parents(
BoxedSlicePrefix([
BlockId(0x2f68b25006f0e1b55ada3e9278e69796380971e97587c233d138c593139d255d),
BlockId(0x76d25ac0073d14381d9a38c61ecb9665241d771bd89564e467c7fdf98e770ddd),
BlockId(0xd072addb86a5a59a69b17d0e8fc3368771dc5ea7f7c2257045e508ae37f27a46),
BlockId(0xfea2e90318a1b234569a3d698e97906d2c6a0084eb571971bf9ce9c4d31ee6c9),
]),
),
payload: OptionalPayload(
None,
),
nonce: 4420,
}
Block with no payload sent: https://explorer.shimmer.network/testnet/block/0x9f794dde42c7be9cd209cc992f69e1f8b7b40578303825049079d8ac128aa20f