Building blocks for Stylus smart contract development
- Create new project
cargo stylus new my-cool-project --minimal
- Import
stylus-toolkit
as dependency in theCargo.toml
stylus-toolkit = { git = "https://github.com/LimeChain/stylus-toolkit.git", branch = "main" }
- Import the desired contracts into your source files
ERC20 Example
use stylus_toolkit::tokens::erc20::{Erc20, Erc20Params};
struct MyParams;
impl Erc20Params for MyParams {
const NAME: &'static str = "Dummy ERC20 token";
const SYMBOL: &'static str = "DERC20";
const DECIMALS: u8 = 18;
}
sol_storage! {
#[entrypoint]
struct DummyErc20 {
#[borrow] // Allows erc20 to access Dummy Erc20's storage and make calls
Erc20<MyParams> erc20;
}
}
#[external]
#[inherit(Erc20<MyParams>)]
impl DummyrErc20 {}
ED25519 Signature Verification
use stylus_toolkit::crypto::ed25519::ed25519_verify;
sol_storage! {
#[entrypoint]
struct Ed25519Verify { }
}
#[external]
impl Ed25519Verify {
pub fn verify(
&mut self,
msg: Bytes,
signature: Bytes,
public_key: FixedBytes<32>,
) -> Result<(bool), Vec<u8>> {
Ok(ed25519_verify(public_key, signature, msg))
}
}
- Build the project
cargo build --package my-cool-project --release
- Sanity check the source code for activation prior to deployment
cargo stylus check
- Deploy contracts
cargo stylus deploy -e $RPC --private-key $PK