3

I'm fairly new to Rust and ink! itself.

I'm trying to compile and build an extremely basic PSP22 Contract.

I get the following error when I compile & build:

(running cargo +nightly contract build)

enter image description here

The following is my Contract (lib.rs) :

#![cfg_attr(not(feature = "std"), no_std)]
#![feature(min_specialization)]
        
#[openbrush::contract]
pub mod my_psp22 {
    
    // imports from openbrush
    use openbrush::contracts::psp22::*;
    use openbrush::traits::Storage;

    #[ink(storage)]
    #[derive(Default, Storage)]
    pub struct Ipsp22 {
        #[storage_field]
        psp22: psp22::Data,
    }
    
    // Section contains default implementation without any modifications
    impl PSP22 for Ipsp22 {}
     
    impl Ipsp22 {
        #[ink(constructor)]
        pub fn new(initial_supply: Balance) -> Self {
            let mut _instance = Self::default();
            _instance._mint_to(_instance.env().caller(), initial_supply).expect("Should mint"); 
            _instance
        }
    }
}

And here is my Cargo.toml :

[package]
name = "my_token"
version = "0.1.0"
authors = ["0xD1x0n"]
edition = "2021"
license = "Apache 2.0"

[dependencies]
ink = { version = "~4.0.0", default-features = false }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts/", tag = "3.0.0", default-features = false, features = ["psp22", "ownable"] }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

[lib]
name = "my_token"
path = "lib.rs"
crate-type = [
    "cdylib",
    "rlib",
]

[features]
default = ["std"]
std = [
    "ink/std",
    "scale/std",
    "scale-info/std",
    "openbrush/std",
]
ink-as-dependency = []

I am using the following versions of these tools:

  • rustc 1.69.0 (84c898d65 2023-04-16)
  • cargo-contract-contract 2.2.1-91b5a86-aarch64-apple-darwin
  • rustup 1.26.0 (5af9b9484 2023-04-05)

I'm not quite sure why its happening, any help would be deeply appreciated

2 Answers 2

1

I made these changes to your code and it compiled successfully:

changes to code shown in the question to make it work

I was using these versions:

rustc 1.69.0 (84c898d65 2023-04-16)
cargo-contract-contract 3.0.1-unknown-x86_64-unknown-linux-gnu
rustup 1.26.0 (5af9b9484 2023-04-05)

I was running it in a Docker container running:

Debian GNU/Linux 11 (bullseye)

I ran it with the following and it worked:

cargo +nightly-2023-03-21-x86_64-unknown-linux-gnu contract build
9
  • Could you share your Docker file ?
    – 0xD1x0n
    Commented Jun 20, 2023 at 23:51
  • I got this error along with hundreds other similar to it : error[E0152]: duplicate lang item in crate alloc (which std depends on): owned_box.
    – 0xD1x0n
    Commented Jun 21, 2023 at 4:30
  • 1
    i've added it in this PR github.com/ltfschoen/InkTemplate/pull/17/… including instructions. so just need to install Docker then run something like touch .env && cp .env.example .env && time ./docker/docker.sh, then run docker exec -it ink /bin/bash in two terminals, and inside one terminal start a substrate-contracts-node with cd /app && ./docker/reset.sh, and in the other terminal run cd /app && ./docker/quickstart-ipsp22.sh to build and deploy and instantiate that smart contract Commented Jun 21, 2023 at 7:54
  • 1
    the dockerfile that it uses is here github.com/ltfschoen/InkTemplate/blob/main/docker/Dockerfile Commented Jun 21, 2023 at 10:22
  • I got to the part where I open up 2 terminals using : docker exec -it ink /bin/bash. Looks like there is no app folder in it. the docker folder it contains only has a run.sh file in it.
    – 0xD1x0n
    Commented Jun 21, 2023 at 18:37
0

Resolved by using this as my Cargo.toml :

[package]
name = "alephcontract"
version = "1.0.0"
edition = "2021"
authors = ["0xD1x0n"]

[dependencies]
ink = { version = "4.2.1", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", tag = "3.1.0", default-features = false, features = ["psp22","ownable",]}

[lib]
name = "alephcontract"
path = "lib.rs"
crate-type = [
    # Used for normal contract Wasm blobs.
    "cdylib",
    "rlib",
]

[features]
default = ["std"]
std = [
    "ink/std",
    "scale/std",
    "scale-info/std",
    "openbrush/std",
]

psp22 = ["openbrush/psp22"]
ink-as-dependency = []

I compiled the contract using toolchain +nightly-2023-01-01 by executing the following command :

cargo +nightly-2023-01-01 contract build --release

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.