10

I having some trouble running the Flipper example from the Ink! webpage.

The cargo contract build outputs the following error log:

ERROR: Loading of original wasm failed

Caused by:
    0: Loading of wasm module at '/Users/winston/workspace/cs/repos/flipper/target/ink/wasm32-unknown-unknown/release/flipper.wasm' failed
    1: Unknown opcode 192

rustup show output:

Default host: aarch64-apple-darwin
rustup home:  /Users/winston/.rustup

installed toolchains
--------------------

stable-aarch64-apple-darwin
nightly-aarch64-apple-darwin (default)

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
wasm32-unknown-unknown
wasm32-wasi

active toolchain
----------------

nightly-aarch64-apple-darwin (default)
rustc 1.70.0-nightly (17c116721 2023-03-29)

As you can see, I am running on the M1 OSX system.

3
  • 1
    Please, remember to mark this question as solved :) Mar 30 at 17:02
  • Rustc v1.70.0 dont work either so consider sticking with 1.68.0 or 1.69.0 stable Jun 8 at 11:29
  • I'm running into this in 1.71.1 - what might be the reason?
    – shredding
    Aug 6 at 9:50

4 Answers 4

11

Solved! This was caused by the nightly toolchain. Switching to the stable toolchain solved this issue.

Edit: As pointed out by Shunsuke, this is specific to the 1.70.0 nightly build. 1.68.0 version seems to work.

Edit (12th June 2023): If you are using the latest version 3.0.1 of cargo-contract --version then you must fallback to 1.69 (since neither stable or nightly 1.70.0 worked). The CI for cargo-contract has pinned that version, see https://github.com/paritytech/cargo-contract/blob/master/.github/workflows/ci.yml#LL184C62-L184C118

rustup update stable
rustup install 1.69
rustup default 1.69
rustup component add rust-src --toolchain 1.69
rustup target add wasm32-unknown-unknown --toolchain 1.69
cargo contract build
4
  • 1
    Lots of contracts including OpenBrush PSP22, PSP34 contracts using nightly features such as #![feature(min_specialization)]. This means existing contracts cannot be compiled with nightly toolchain whose rustc version is higher than 1.70.0 (Confirmed 1.68.0 works). cargo contract is now independent from nightly toolchain but it should still support nightly for compatibility.
    – Shunsuke
    Mar 31 at 7:41
  • 2
  • I just had this issue both using 1.70.0 stable & nightly. Fixed by changing back to 1.69 by running rustup update && rustup install 1.69 && rustup default 1.69 && rustup override set 1.69 && rustup component add rust-src --toolchain 1.69 && cargo contract build. Note that cargo-contract has pinned their CI to 1.69 github.com/paritytech/cargo-contract/blob/master/.github/… due to this issue github.com/paritytech/cargo-contract/issues/1139. Jun 11 at 23:57
  • I was tired to try everything, but this works, even at the end I got this issue info: installing component 'rust-std' for 'wasm32-unknown-unknown' 18.2 MiB / 18.2 MiB (100 %) 17.3 MiB/s in 1s ETA: 0s ERROR: Cannot infer the root project id. Also I aded the rust-toolchain with nightly-2023-02-07" and cargo-contract version cargo-contract v2.2.1 `
    – Cristian
    Aug 28 at 1:29
4

For cases where updated nightly is still preferred for whatever reason:

rustup update
rustup install nightly-2023-02-07-aarch64-apple-darwin
rustup component add rust-src --toolchain nightly-2023-02-07-aarch64-apple-darwin

...specify nightly version in tag

cargo +nightly-2023-02-07 contract build

Still running updated nightly rustc 1.70.0 as default: image

1

Adding a rust toolchain override file can also work.

Such as this:

[toolchain]
channel = "nightly-2023-01-01"
components = [ "rustfmt" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
1

ran into the same issue using v3.0 cargo contract , updating cargo contract to v4 solved it. Use

cargo install --git https://github.com/paritytech/cargo-contract cargo-contract --force

to update

1
  • you can also leave your rustc version as is... no need to downgrade
    – Honour
    Aug 2 at 14:33

Your Answer

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

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