5

so I am migrating my contract from version 3 to 4 my goal is to use the open brush as well but we can not use the open brush in ink version 4 because it still needs the nightly features and Ink v4 runs on stable.

this is my current manifest file enter image description here

now this works fine as long as I am building on nightly cargo +nightly contract build --release

but I have a function that needs to convert a FixesI128 [from fixed crate] to string which is where the issue is

enter image description here

everything is fine in this function except the highlighted line so with this line, if I build a contract [on nightly] I get this error

enter image description here

but if I remove this line this compiles down successfully

also, one more thing I am using String from Openbrush and to string from ink prelude as you can see in the picture

enter image description here

please let me know if there is any solution

3
  • github.com/paritytech/cargo-contract/issues/…
    – go11li
    Commented May 6, 2023 at 1:13
  • you can fix this issue using above link @Rahul navgire
    – go11li
    Commented May 6, 2023 at 1:13
  • i've got two comments to share. firstly you might be able to resolve that ERROR: Loading of original wasm failed ... Unknown opcode 192 shown in your screenshot by following the steps i mentioned in this other issue substrate.stackexchange.com/questions/7881/… (i.e. use rust 1.69, not 1.70). secondly, if the value of b is 0, then your line let res = a / b might result in overflow error. so i suggest seeing if you can use checked_div, and also make your return value a Result<()>, so you return Ok or Err. Commented Jun 15, 2023 at 11:00

1 Answer 1

4

EDIT: this is not completely correct answer anymore. Openbrush is using String type from ink! prelude since version 3.0.0

pub type String = ink::prelude::string::String;

When you look at the definition of openbrush::traits::String you can see that OB String is actually a vector Vec<u8>

pub struct String {
    vec: Vec<u8>,
}

One way to have both types of strings used is to use aliases:

use ink::prelude::string::{String as PreludeString};
use openbrush::traits::String;

Depending on your needs you can use either of them or both. I find using from to be more convenient than to_string()

// ink::prelude's String
let s = PreludeString::from(res_str)

// OB version 
let s = String::from(res_str)

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.