Arbitrum Stylus logo

Stylus by Example

Bytes In, Bytes Out

This is a simple bytes in, bytes out contract that shows a minimal entrypoint function (denoted by the #[entrypoint] proc macro). If your smart contract just has one primary function, like computing a cryptographic hash, this can be a great model because it strips out the SDK and acts like a pure function or Unix-style app.

src/main.rs

1#![cfg_attr(not(feature = "export-abi"), no_main)]
2
3extern crate alloc;
4use alloc::vec::Vec;
5
6use stylus_sdk::stylus_proc::entrypoint;
7
8#[entrypoint]
9fn user_main(input: Vec<u8>) -> Result<Vec<u8>, Vec<u8>> {
10    Ok(input)
11}
1#![cfg_attr(not(feature = "export-abi"), no_main)]
2
3extern crate alloc;
4use alloc::vec::Vec;
5
6use stylus_sdk::stylus_proc::entrypoint;
7
8#[entrypoint]
9fn user_main(input: Vec<u8>) -> Result<Vec<u8>, Vec<u8>> {
10    Ok(input)
11}

Cargo.toml

1[package]
2name = "bytes_in_bytes_out"
3version = "0.1.7"
4edition = "2021"
5
6[dependencies]
7stylus-sdk = "0.6.0"
8
9[features]
10export-abi = ["stylus-sdk/export-abi"]
11
12[profile.release]
13codegen-units = 1
14strip = true
15lto = true
16panic = "abort"
17opt-level = "s"
18
19[workspace]
1[package]
2name = "bytes_in_bytes_out"
3version = "0.1.7"
4edition = "2021"
5
6[dependencies]
7stylus-sdk = "0.6.0"
8
9[features]
10export-abi = ["stylus-sdk/export-abi"]
11
12[profile.release]
13codegen-units = 1
14strip = true
15lto = true
16panic = "abort"
17opt-level = "s"
18
19[workspace]