Crates.io | spawn-wasm-erc721 |
lib.rs | spawn-wasm-erc721 |
version | 0.1.4 |
source | src |
created_at | 2024-09-06 03:47:28.347129 |
updated_at | 2024-09-11 07:46:34.279759 |
description | A Rust library for creating ERC-721 compliant Non-Fungible Tokens (NFTs) with WebAssembly (WASM) support. |
homepage | |
repository | https://github.com/nzengi/spawn-wasm-erc721 |
max_upload_size | |
id | 1365487 |
size | 19,682 |
spawn-wasm-erc721
is a Rust library designed to handle ownership and user roles for smart contracts in a WebAssembly (WASM) environment. This library provides essential functionality for role management, including assigning roles to users, checking role-based access, and transferring ownership.
To use the library, first add the following dependencies to your Cargo.toml
file:
[dependencies]
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["console"] }
Also, ensure the following settings are added to your Cargo.toml for WebAssembly compilation:
[lib]
crate-type = ["cdylib"]
[profile.release]
lto = true
[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-Oz"]
Initialize RoleManager To initialize the RoleManager struct with an owner:
use spawn_wasm_erc721::RoleManager;
let owner = "owner1".to_string();
let mut role_manager = RoleManager::new(owner);
Assign a role to a user, ensuring the caller is the owner:
role_manager.assign_role("owner1".to_string(), "admin".to_string(), "user1".to_string());
Check if a user has access based on a specific role:
let has_access = role_manager.role_based_access("user1".to_string(), "admin".to_string());
Ownership can only be transferred by the current owner:
role_manager.transfer_ownership("owner1".to_string(), "new_owner".to_string());
To list all users with a specific role:
let users = role_manager.list_role_users("admin".to_string());