Got a killer idea? Need some support to make it happen? Let’s build a crowdfunding smart contract with Rust on the MultiversX Network! This will let anyone pitch in to fund projects, and you’ll have full control over managing the funds once the goal is reached!
What You’ll Need
Rust and sc-meta — Get it up and running following this guide.
Install Rust (if not already installed): First, ensure you have Rust installed by running:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Then, verify the installation by checking the version:
rustc --version
Install sc-meta: To set up sc-meta, you can typically install it via cargo (Rust's package manager):
cargo install multiversx-sc-meta --locked
Once sc-meta is ready, install the wasm32 target (for the Rust compiler), wasm-opt, and others dependencies as follows:
\# Installs `wasm32`, `wasm-opt`, and others in one go:
sc-meta install all
cargo install twiggy
If any error occurs during the installation process, please refer here.
VS Code Extensions — Grab rust-analyzer and CodeLLDB to supercharge your coding environment.
Setting Up the Workspace
First things first, we need a place to build this beauty. Let’s create a project folder and get things rolling!
Create the project folder:
mkdir -p ~/MultiversX/SmartContracts
Change directory to newly created folder:
cd ~/MultiversX/SmartContracts
Initialize a new MultiversX smart contract:
sc-meta new --name crowdfunding --template empty
Open the project in Visual Studio Code:
code crowdfunding
Writing the Initial Code
To start simple, let’s initialize the contract file. Open up src/crowdfunding.rs and replace everything with this basic starter code:
#!\[no_std\]
multiversx_sc::imports!();
#\[multiversx_sc::contract\]
pub trait Crowdfunding {
#\[init\]
fn init(&self) {
}
}
That’s it! A very chill beginning, just to set things up. Next, we’ll start building the real deal.
Swap insights and ask questions about “Build on MultiversX”.
Ask a question or share your thoughts about this lesson.