bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 24쪽
/index
Resources for learning about EVM development, from Solidity basics to low-level assembly languages.
<CardGroup>
<Card title="Solidity Resources" href="/guides/evm-resources/solidity-resources">
A comprehensive guide to learning Solidity, from beginner to advanced
</Card>
<Card title="EVM Behavior" href="/guides/evm-resources/evm-behavior">
EVM behavioral specification, opcode reference, and storage layout
</Card>
<Card title="Other Languages" href="/guides/evm-resources/other-languages">
Resources for Vyper and Yul
</Card>
</CardGroup>
# How to Consume Execution Events in Rust
Source: https://docs.monad.xyz/guides/execution-events/consume-rust
# How to Consume Execution Events in Rust: A Basic Example
This guide walks through building a minimal Rust application that reads execution events from a live Monad node. By the end of this guide, you'll have a working event consumer that prints each EVM action as it happens.
<iframe title="YouTube video player" />
## Prerequisites
This guide assumes you have:
* A running Monad node with execution events enabled ([setup guide](/guides/execution-events/setup))
## Project Setup
Here is the [repo with the code](https://github.com/portdeveloper/simple-execution-events).
Create a new Rust project:
```bash theme={null}
cargo new --bin exec-events-demo
cd exec-events-demo
```
Replace `Cargo.toml` with:
```toml theme={null}
[package]
name = "exec-events-demo"
version = "0.1.0"
edition = "2021"
[dependencies]
monad-exec-events = { git = "https://github.com/category-labs/monad-bft", tag = "release/exec-events-sdk-v1.0" }
monad-event-ring = { git = "https://github.com/category-labs/monad-bft", tag = "release/exec-events-sdk-v1.0" }
```
## The Code
Replace `src/main.rs` with:
```rust title="src/main.rs" theme={null}
use std::time::Duration;
use monad_event_ring::{DecodedEventRing, EventNextResult, EventPayloadResult, EventRingPath};
use monad_exec_events::{ExecEvent, ExecEventReaderExt, ExecEventRing, ExecEventType};
/// Default path for the execution event ring
const EVENT_RING_PATH: &str =
"/var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings/monad-exec-events";
fn main() {
// Resolve the event ring path (full path bypasses hugetlbfs lookup)
let event_ring_path =
EventRingPath::resolve(EVENT_RING_PATH).expect("Failed to resolve path");
// Open the live event ring
let ring = ExecEventRing::new(&event_ring_path).expect("Failed to open event ring");
println!("Connected to event ring");
println!("Waiting for events...\n");
// Create a reader and rewind to the start of the current block
let mut reader = ring.create_reader();
reader.consensus_prev(Some(ExecEventType::BlockStart));
loop {
match reader.next_descriptor() {
EventNextResult::Ready(event) => {
let seqno = event.info().seqno;
// Try to read the event payload
match event.try_read() {
EventPayloadResult::Ready(exec_event) => {
print_event(&exec_event, seqno);
}
EventPayloadResult::Expired => {
eprintln!("[{}] Payload expired!", seqno);
reader.reset();
}
}
}
EventNextResult::Gap => {
eprintln!("Warning: event gap occurred (reader too slow)");
reader.reset();
}
EventNextResult::NotReady => {
// No events available, wait briefly
std::thread::sleep(Duration::from_millis(10));
}
}
}
}
fn print_event(event: &ExecEvent, seqno: u64) {
match event {
ExecEvent::BlockStart(block) => {
println!(
"[{}] BLOCK_START: number={}",
seqno, block.block_tag.block_number
);
}
ExecEvent::BlockEnd(_) => {
println!("[{}] BLOCK_END", seqno);
}
ExecEvent::TxnHeaderStart { txn_index, .. } => {
println!("[{}] TXN_START: index={}", seqno, txn_index);
}
ExecEvent::TxnEvmOutput { txn_index, output } => {
println!(
"[{}] TXN_OUTPUT: index={} gas_used={}",
seqno, txn_index, output.receipt.gas_used
);
}
ExecEvent::TxnLog { txn_index, txn_log, .. } => {
println!(
"[{}] LOG: txn={} topics={}",
seqno, txn_index, txn_log.topic_count
);
}
ExecEvent::TxnEnd => {
println!("[{}] TXN_END", seqno);
}
// Silently ignore other events (call frames, storage access, etc.)
_ => {}
}
}
```
## Build and Run
```bash theme={null}
cargo build --release
./target/release/exec-events-demo
```
## Expected Output
You'll see a stream of events as your node processes transactions:
```
Connected to event ring
Waiting for events...
[508183802] BLOCK_START: number=45199825
[508183811] TXN_START: index=0
[508183822] TXN_OUTPUT: index=0 gas_used=0
[508183823] LOG: txn=0 topics=3
[508183838] TXN_END
[508183942] BLOCK_END
```
## Key Concepts
### Event Ring
The event ring is a shared memory buffer where the execution daemon writes events. Multiple readers can consume from it simultaneously, each maintaining their own position.
### EventNextResult
* **Ready**: An event is available to process
* **NotReady**: No new events yet (daemon hasn't written any)
* **Gap**: Reader fell behind and events were overwritten - call `reset()` to recover
### Event Types
Common events you'll see:
* `BlockStart` / `BlockEnd` - Block boundaries
* `TxnHeaderStart` / `TxnEnd` - Transaction boundaries
* `TxnEvmOutput` - Transaction execution result (contains receipt with gas\_used)
* `TxnLog` - EVM log emission (Solidity events)
* `AccountAccess` - Account touched during execution
* `StorageAccess` - Contract storage read/write
## Next Steps
* See the full [eventwatch.rs](https://github.com/category-labs/monad-bft/blob/release/exec-events-sdk-v1.0/monad-exec-events/examples/eventwatch.rs) example for production patterns (timestamps, timeout detection, CLI args)
* Read the [Rust API docs](/execution-events/rust-api) for detailed type information
* Explore the [event ring internals](/execution-events/event-ring) to understand the shared memory protocol
# How to accelerate your app with Execution Events
Source: https://docs.monad.xyz/guides/execution-events/index
<CardGroup>
<Card title="Set up Execution Events" href="/guides/execution-events/setup">
Configure your Monad node to enable execution events
</Card>
<Card title="Consume Events in Rust" href="/guides/execution-events/consume-rust">
Build a Rust application to read execution events
</Card>
</CardGroup>
# Set up Execution Events
Source: https://docs.monad.xyz/guides/execution-events/setup
This guide walks you through configuring your Monad node to enable the Execution Events system, which allows you to build high-performance applications that receive lowest-latency event data via shared memory.
## Prerequisites
* A running Monad full node ([full node installation guide](/node-ops/full-node-installation))
* A stable way to access the node
<Info title="Why execution events?">
Monad produces blocks every 300 milliseconds and can process thousands of transactions per block. Traditional JSON-RPC and WebSocket APIs may not keep up with this data volume. Execution events provide the highest-throughput, lowest-latency option for consuming real-time blockchain data.
For more details, see the [Execution Events documentation](/execution-events/).
</Info>
## Step 1: Install required packages
Install the `hugeadm` utility for managing huge pages:
```bash theme={null}
sudo apt install libhugetlbfs-bin
```
<Accordion title="Behind the scenes">
Installs the `libhugetlbfs-bin` package, which provides the `hugeadm` command-line tool. This tool manages "huge pages" - large memory pages (2MB instead of the standard 4KB) that reduce memory management overhead and improve performance for applications that need to share large amounts of data quickly, like execution events.
</Accordion>
If you plan to write applications using the Execution Events SDK (C, C++, or Rust), also install these development packages:
```bash theme={null}
sudo apt install libhugetlbfs-dev libhugetlbfs0 libzstd-dev
```
<Accordion title="Behind the scenes">
* **libhugetlbfs-dev**: Header files for developing applications that use huge pages
* **libhugetlbfs0**: Runtime library for huge page support
* **libzstd-dev**: Zstandard compression library, used for efficient data encoding in the SDK
</Accordion>
## Step 2: Set up the `hugetlbfs` mount
The execution events system uses huge pages for high-performance shared memory communication. You need to create a persistent `hugetlbfs` mount.
### Create a systemd service for persistent mounts
Create the service file:
```bash theme={null}
sudo nano /etc/systemd/system/events-hugepages-mounts.service
```
Paste the following contents (replace `monad` with your user if different):
```ini theme={null}
[Unit]
Description=Create hugepage mounts for monad
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/bin/hugeadm --create-user-mounts monad
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
```
<Accordion title="Behind the scenes">
This systemd service runs `hugeadm --create-user-mounts monad` at boot time, which:
* Creates a `hugetlbfs` filesystem mount at `/var/lib/hugetlbfs/user/monad/`
* Sets up separate directories for different page sizes (2MB and 1GB)
* Ensures the `monad` user has permission to create files in these directories
The `Type=oneshot` means it runs once at startup, and `RemainAfterExit=yes` keeps the service marked as "active" so systemd knows the mount is still needed.
</Accordion>
Save and exit (`Ctrl+O`, `Enter`, `Ctrl+X`).
Enable and start the service:
```bash theme={null}
sudo systemctl daemon-reload
sudo systemctl enable --now events-hugepages-mounts
```
<Accordion title="Behind the scenes">
* **daemon-reload**: Tells systemd to re-read all service files, picking up your new service
* **enable --now**: Enables the service to start at boot AND starts it immediately
After this, the hugepage mount will be available now and on every reboot.
</Accordion>
## Step 3: Create the event-rings directory
The execution daemon writes event data to files in this directory:
```bash theme={null}
sudo mkdir -p /var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings
sudo chown monad:monad /var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings
```
<Accordion title="Behind the scenes">
* **mkdir -p**: Creates the `event-rings` directory (and any parent directories if needed)
* **chown monad:monad**: Changes ownership to the `monad` user so the execution daemon can write event ring files here
The path `/var/lib/hugetlbfs/user/monad/pagesize-2MB/` is where `hugeadm` created the 2MB huge page mount. The execution daemon will create shared memory files in `event-rings/` that your consumer applications can read.
</Accordion>
<Note>
Replace `monad` with your actual user if you're running the node as a different user.
</Note>
## Step 4: Configure the Execution daemon
Create a systemd override to enable execution events output.
Open the override editor:
```bash theme={null}
sudo systemctl edit monad-execution
```
<Accordion title="Behind the scenes">
Opens a text editor to create an "override" file for the `monad-execution` service. Overrides let you modify service settings without editing the original unit file (which would be overwritten on package updates). The override file is saved at `/etc/systemd/system/monad-execution.service.d/override.conf`.
</Accordion>
Add the following configuration:
```ini theme={null}
[Service]
ExecStart=
ExecStart=/usr/local/bin/monad \
--chain "$CHAIN" \
--db /dev/triedb \
--block_db /home/monad/monad-bft/ledger \
--statesync /home/monad/monad-bft/statesync.sock \
--exec-event-ring /var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings/monad-exec-events \
--sq_thread_cpu 1 \
--log_level INFO
```
<Accordion title="Behind the scenes">
* **ExecStart=** (empty): Clears the original command from the base unit file (required for overrides)
* **ExecStart=/usr/local/bin/monad ...**: Sets the new command with all flags
* **--exec-event-ring**: The key flag that enables execution events output. It specifies the path where the daemon will create the shared memory event ring file
The other flags are standard execution daemon options copied from the default configuration.
</Accordion>
<Warning>
Both `ExecStart=` lines are required. The first clears the original value, and the second sets the new value with the `--exec-event-ring` flag.
</Warning>
Reload and restart the Execution daemon:
```bash theme={null}
sudo systemctl daemon-reload
sudo systemctl restart monad-execution
```
<Accordion title="Behind the scenes">
* **daemon-reload**: Tells systemd to re-read all service files, including your new override
* **restart monad-execution**: Stops and starts the execution daemon with the new configuration
After restart, the daemon will begin writing execution events to the shared memory ring buffer.
</Accordion>
## Step 5: Configure the RPC daemon for WebSocket support
This step enables WebSocket support in the RPC server, allowing you to use `eth_subscribe` for real-time data.
<Warning>
RPC with WebSocket enabled has a hard dependency on Execution running with events enabled. If you start RPC with `--ws-enabled` before completing Step 4, RPC will crash.
</Warning>
Open the RPC override editor:
```bash theme={null}
sudo systemctl edit monad-rpc
```
<Accordion title="Behind the scenes">
Creates an override file at `/etc/systemd/system/monad-rpc.service.d/override.conf` to customize the RPC service configuration.
</Accordion>
Add the following configuration:
```ini theme={null}
[Service]
ExecStart=
ExecStart=/usr/local/bin/monad-rpc \
--ipc-path /home/monad/monad-bft/mempool.sock \
--triedb-path /dev/triedb \
--otel-endpoint "http://0.0.0.0:4317" \
--allow-unprotected-txs \
--node-config /home/monad/monad-bft/config/node.toml \
--exec-event-path /var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings/monad-exec-events \
--ws-enabled
```
<Accordion title="Behind the scenes">
* **ExecStart=** (empty): Clears the original command from the base unit file (required for overrides)
* **--exec-event-path**: Points to the same event ring file that the Execution daemon writes to
* **--ws-enabled**: Enables WebSocket support on port 8081 (default)
</Accordion>
Reload and restart the RPC daemon:
```bash theme={null}
sudo systemctl daemon-reload
sudo systemctl restart monad-rpc
```
<Accordion title="Behind the scenes">
* **daemon-reload**: Tells systemd to re-read all service files, including your new override
* **restart monad-rpc**: Stops and starts the RPC daemon with WebSocket support enabled
</Accordion>
## Step 6: Verify the setup
Check that the event ring file has been created:
```bash theme={null}
ls -la /var/lib/hugetlbfs/user/monad/pagesize-2MB/event-rings/
```
<Accordion title="Behind the scenes">
Lists the contents of the event-rings directory. You should see a file named `monad-exec-events`. This is the shared memory file that the execution daemon writes to and your consumer applications read from.
</Accordion>
You should see a file named `monad-exec-events` (or similar).
Check the Execution daemon status:
```bash theme={null}
sudo systemctl status monad-execution
```
<Accordion title="Behind the scenes">
Shows the current status of the execution daemon service. Look for:
* **Active: active (running)** - the service is running
* No error messages in the recent log output
If you see errors related to the event ring or hugepages, check the Troubleshooting section below.
</Accordion>
The service should be active and running without errors.
### Check WebSocket connectivity
A quick way to check if WebSocket connectivity is working is to use [`websocat`](https://github.com/vi/websocat), a command-line WebSocket client. It can be installed via `cargo install websocat` or by downloading precompiled binaries.
Run it in verbose mode with the WebSocket service on default port 8081:
```bash theme={null}
websocat -v ws://localhost:8081
```
You should see output like:
```
[INFO websocat::lints] Auto-inserting the line mode
[INFO websocat::stdio_threaded_peer] get_stdio_peer (threaded)
[INFO websocat::ws_client_peer] get_ws_client_peer
[INFO websocat::net_peer] Connected to TCP 127.0.0.1:8081
[INFO websocat::ws_client_peer] Connected to ws
[INFO websocat::ws_peer] Received WebSocket ping
```
To subscribe to new block headers, type this JSON-RPC call and press enter:
```json theme={null}
{ "id": 1, "jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newHeads"] }
```
Every half-second or so, you should see updates about new blocks.
## Next steps
With execution events and WebSocket support enabled, you can now:
* **Build your own data consumer**: Write high-performance applications in C, C++, or Rust using the Execution Events SDK. See the [Getting Started guide](/execution-events/getting-started/) for examples.
* **Learn more about WebSocket subscriptions**: See the [WebSocket Guide](/reference/websockets) for all available subscription types.
## Troubleshooting
### Event ring file not created
Ensure the hugepage mount is active:
```bash theme={null}
mount | grep hugetlbfs
```
<Accordion title="Behind the scenes">
Lists all mounted filesystems and filters for `hugetlbfs` mounts. You should see output like:
```
hugetlbfs on /var/lib/hugetlbfs/user/monad/pagesize-2MB type hugetlbfs (rw,relatime,...)
```
If there's no output, the hugepage mount isn't active.
</Accordion>
You should see a mount point like `/var/lib/hugetlbfs/user/monad/pagesize-2MB`.
If not, restart the hugepages service:
```bash theme={null}
sudo systemctl restart events-hugepages-mounts
```
<Accordion title="Behind the scenes">
Re-runs the hugepage mount service, which will recreate the `hugetlbfs` mount points. After this, run the `mount | grep hugetlbfs` command again to verify.
</Accordion>
### Execution daemon fails to start
Check the logs for errors:
```bash theme={null}
sudo journalctl -u monad-execution -f
```
<Accordion title="Behind the scenes">
* **journalctl -u monad-execution**: Shows logs for the execution daemon service
* **-f**: Follows the log in real-time (like `tail -f`)
Press `Ctrl+C` to stop following. Look for error messages mentioning the event ring path, permissions, or hugepages.
</Accordion>
Common issues:
* The `event-rings` directory doesn't exist or has wrong permissions
* The hugepage mount is not available
* Incorrect paths in the systemd override
### Permission denied errors
Ensure the `event-rings` directory is owned by the correct user:
```bash theme={null}
sudo chown -R monad:monad /var/lib/hugetlbfs/user/monad/
```
<Accordion title="Behind the scenes">
Recursively changes ownership of the entire hugepage directory tree to the `monad` user. The `-R` flag ensures all subdirectories and files are updated.
</Accordion>
## Further resources
* [Execution Events documentation](/execution-events/) - Comprehensive documentation on the execution events system
* [Execution Events overview](/execution-events/overview) - Core concepts and event types
* [C API reference](/execution-events/c-api) - C library documentation
* [Rust API reference](/execution-events/rust-api) - Rust crate documentation
* [Execution Events and WebSocket Setup](/node-ops/events-and-websockets) - Enable WebSocket support in RPC
# Guides
Source: https://docs.monad.xyz/guides/index
Start building smart contracts and applications on Monad with our quickstart guides.
## Get a wallet
<CardGroup>
<Card title="MetaMask" href="https://metamask.io/download/">
MetaMask browser wallet
</Card>
<Card title="Software Wallets" href="/tooling-and-infra/wallets/software-wallets">
Select a browser wallet
</Card>
</CardGroup>
## Deploy Smart Contract
<CardGroup>
<Card title="Foundry" href="/guides/deploy-smart-contract/foundry">
Deploy a smart contract on Monad using Foundry
</Card>
<Card title="Hardhat" href="/guides/deploy-smart-contract/hardhat">
Deploy a smart contract on Monad using Hardhat
</Card>
<Card title="Remix" href="/guides/deploy-smart-contract/remix">
Deploy a smart contract on Monad 프로젝트로 돌아가기