Back to Learn
basic examples
Hello World
Write your first Stylus contract using the console! macro for debugging.
Hello World
The console! macro from the Stylus SDK allows you to print output to the terminal for debugging purposes.
Setup Requirements
1. Run a local Stylus dev node
2. Enable the debug feature in Cargo.toml
Usage
The console! macro works similar to Rust's println! macro:
``rust
console!("hello there!");
console!("format {} arguments", "some");
``Important Notes
- Debug output only works on local dev nodes
- Remove console! calls before mainnet deployment
- The debug feature must be enabled in your Cargo.toml
Code Example
#![cfg_attr(not(feature = "export-abi"), no_main)]
extern crate alloc;
use stylus_sdk::{console, prelude::*};
#[storage]
#[entrypoint]
pub struct Hello;
#[public]
impl Hello {
fn user_main(&self) -> Result<(), Vec<u8>> {
console!("Hello Stylus!");
Ok(())
}
}