Skip to main content

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

#![no_main]
#![no_std]
extern crate alloc;

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
use alloc::vec::Vec;

use stylus_sdk::stylus_proc::entrypoint;

#[entrypoint]
fn user_main(input: Vec<u8>) -> Result<Vec<u8>, Vec<u8>> {
Ok(input)
}

Cargo.toml

[package]
name = "bytes_in_bytes_out"
version = "0.1.0"
edition = "2021"

[dependencies]
stylus-sdk = "0.4.2"
wee_alloc = "0.4.5"

[features]
export-abi = ["stylus-sdk/export-abi"]

[profile.release]
codegen-units = 1
strip = true
lto = true
panic = "abort"
opt-level = "s"

[workspace]