Rise In Logo

Build on MultiversX

Welcome to MultiversX!

Simple Crowdfunding Smart Contract on MultiversX Part-1

Simple Crowdfunding Smart Contract on MultiversX Part-1

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
  • Open Cargo.toml in your new crowdfunding folder. This file holds your dependencies and tells Rust where to find everything. For now, it’ll point to src/crowdfunding.rs as our main file Also:
  • The package is named crowdfunding with a version of 0.0.1. You can change the version, but it must follow the three-number format (e.g., 0.1.0).
  • Dependencies are listed here. Since you're building a Rust smart contract for MultiversX, you'll need specific MultiversX packages.
  • The [lib] section declares the contract's main file, src/crowdfunding.rs, though you can rename it (default Rust naming is lib.rs).
  • The output binary will be named crowdfunding.wasm, based on the crate name, but the .wasm is added by the compiler.

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.


Comments

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!

Disclaimer: The information /programs / events provided on https://patika.dev and https://risein.com are strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice and do not make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://patika.dev and https://risein.com disclaim any responsibility for financial decisions made by users based on information provided here.