#virtual-machine #smart-contracts #contract #virtual #smart #machine #wasm

nightly no-std piecrust-uplink

Build smart contracts directly on top of Dusk’s piecrust virtual machine

28 releases (16 breaking)

new 0.17.3 Dec 19, 2024
0.17.2-rc.0 Nov 26, 2024
0.15.0 Jul 3, 2024
0.11.0 Feb 14, 2024
0.1.0 Mar 15, 2023

#67 in #smart

Download history 63/week @ 2024-08-28 473/week @ 2024-09-04 145/week @ 2024-09-11 229/week @ 2024-09-18 337/week @ 2024-09-25 185/week @ 2024-10-02 255/week @ 2024-10-09 261/week @ 2024-10-16 173/week @ 2024-10-23 125/week @ 2024-10-30 123/week @ 2024-11-06 104/week @ 2024-11-13 182/week @ 2024-11-20 180/week @ 2024-11-27 104/week @ 2024-12-04 341/week @ 2024-12-11

828 downloads per month
Used in 6 crates (3 directly)

MPL-2.0 license

38KB
733 lines

π-crust Uplink

Repository Build Status Documentation

Piecrust Uplink is the library that allows you to build smart contracts directly on top of Dusk's Piecrust virtual machine.

Usage

The library allows users of the contract platform to manage the interface and state with the host environment of the contracts. The example below describes a barebones contract. For more detailed examples, see the contracts folder.

Add piecrust_uplink as a dependency to your contract project:

cargo add piecrust_uplink

To make use of uplink, import the dependency in your project and mark it as no_std:

#![no_std]

use piecrust_uplink as uplink;

To attach state to a contract:

/// Struct that describe the state for your contract
pub struct Counter {
    value: i64,
};

/// State of the contract
static mut STATE: Counter = Counter { value: 0x1 };

To define logic for your contract, define an implementation:

impl Counter {
    pub fn read_value(&self) -> i64 {
        self.value
    }

    pub fn increment(&mut self) {
        let value = self.value + 1;
    }
}

Read and write operations need to be exposed to the host. Add the following below the implementation:

unsafe fn read_value(arg_len: u32) -> u32 {
    uplink::wrap_call(arg_len, |_: ()| STATE.read_value())
}

#[no_mangle]
unsafe fn increment(arg_len: u32) -> u32 {
    uplink::wrap_call(arg_len, |panic: bool| STATE.increment(panic))
}

Release History

To see the release history for this crate, please see the CHANGELOG file.

License

This code is licensed under the Mozilla Public License Version 2.0 (MPL-2.0). Please see the LICENSE for further details.

Contribute

If you want to contribute to this project, please check the CONTRIBUTING file.

Dependencies

~4–11MB
~150K SLoC