Substrate常见问题

1. Rust nightly not installed, please install it!

执行如下命令:

rustup update nightly

2. Rust WASM toolchain not installed, please install it!

 can't find crate for `std`

执行如下命令:

rustup target add wasm32-unknown-unknown --toolchain nightly

3. use pallet::*出错

在这里插入图片描述
cargo build后提示中有这样的信息

--- stderr
     Compiling pallet-strange v4.0.0-dev (/Users/xuanwenchao/Documents/projects/Rust/substrate/substrate-node-template/pallets/strange)
  error: Invalid usage of RuntimeEvent, `Config` contains no associated type `RuntimeEvent`, but enum `Event` is declared (in use of `#[pallet::event]`). An RuntimeEvent associated type must be declare on trait `Config`.

将这个全换成RuntimeEvent后,所有错误全部消失!

4. failed to load manifest for workspace member

error: failed to load manifest for workspace member `/Users/xuanwenchao/Documents/projects/Rust/substrate/substrate-node-template/node`

Caused by:
  failed to load manifest for dependency `node-template-runtime`

Caused by:
  failed to parse manifest at `/Users/xuanwenchao/Documents/projects/Rust/substrate/substrate-node-template/runtime/Cargo.toml`

Caused by:
  could not parse input as TOML

Caused by:
  TOML parse error at line 43, column 1
     |
  43 | }
     | ^
  Could not parse the line

这个错误通常出现在 Cargo.toml 文件中引用的依赖不存在或者路径错误时。请确保依赖的名称和版本号正确,并且在您的 Cargo.toml 文件中使用了正确的路径。

5. error: failed to run custom build command for `node-template-runtime v4.0.0-dev

error: failed to run custom build command for node-template-runtime v4.0.0-dev (/Users/xuanwenchao/Documents/projects/Rust/substrate/substrate-node-template/runtime)
Caused by:
process didn’t exit successfully: /Users/xuanwenchao/Documents/projects/Rust/substrate-node-template/target/debug/build/node-template-runtime-e70130b014f78268/build-script-build (exit status: 101)

rustc --version
rustc 1.68.2 (9eb3afe9e 2023-03-27)
cargo --version
cargo 1.68.2 (6feb7c9cf 2023-03-26)
rustup +nightly show
Default host: aarch64-apple-darwin
rustup home:  /Users/xuanwenchao/.rustup

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

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

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

aarch64-apple-darwin
wasm32-unknown-unknown

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

nightly-aarch64-apple-darwin (overridden by +toolchain on the command line)
rustc 1.70.0-nightly (9df3a39fb 2023-04-11)

执行以下命令、命名用nightly指定版本号

rustup default nightly-2023-01-01

再次执行cargo build后出现了新错误

  --- stderr
  Rust WASM toolchain not installed, please install it!

  Further error information:
  ------------------------------------------------------------
     Compiling wasm-test v1.0.0 (/var/folders/8z/hq_yvw055hg0rt8hkgt75ty00000gn/T/.tmpjVtHMb)
  error[E0463]: can't find crate for `std`
    |
    = note: the `wasm32-unknown-unknown` target may not be installed
    = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
    = help: consider building the standard library from source with `cargo build -Zbuild-std`

  error: requires `sized` lang_item

  For more information about this error, try `rustc --explain E0463`.

这个看提示就好解决了,重新安装wasm toolchain

rustup target add wasm32-unknown-unknown --toolchain nightly
cargo install wasm-bindgen-cli

6. 使用subkey生成公私钥

获取substrate代码

git clone https://github.com/paritytech/substrate.git

编译subkey模块

cargo build -p subkey --release

生成公私钥

./target/release/subkey generate

在这里插入图片描述

7. duplicate definitions with name is_soa

error[E0592]: duplicate definitions with name `is_soa`
   --> /Users/xuanwenchao/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.22.0/src/rr/record_data.rs:55:17
    |
55  | #[derive(Debug, EnumAsInner, PartialEq, Clone, Eq)]
    |                 ^^^^^^^^^^^ duplicate definitions for `is_soa`
...
994 |     pub fn is_soa(&self) -> bool {
    |     ---------------------------- other definition for `is_soa`
    |
    = note: this error originates in the derive macro `EnumAsInner` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0592`.
error: could not compile `trust-dns-proto` due to previous error
warning: build failed, waiting for other jobs to finish...

先将新加的pallet从最外层的cargo.toml中移动确认是否可以编译通过
通常是因为添加依赖时的版本号不一致导致

[dependencies] 
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
	"derive",
] }

8. error[E0583]: file not found for module sys

  error[E0583]: file not found for module `sys`
    --> /Users/xuanwenchao/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.8/src/lib.rs:33:1
     |
  33 | mod sys;
     | ^^^^^^^^
     |
     = help: to create the module `sys`, create file "/Users/xuanwenchao/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.8/src/sys.rs" or "/Users/xuanwenchao/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.8/src/sys/mod.rs"

  error[E0425]: cannot find function `errno` in module `sys`
     --> /Users/xuanwenchao/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.8/src/lib.rs:101:10
      |
  101 |     sys::errno()
      |          ^^^^^ not found in `sys`

  error[E0425]: cannot find function `set_errno` in module `sys`
     --> /Users/xuanwenchao/.cargo/registry/src/github.com-1ecc6299db9ec823/errno-0.2.8/src/lib.rs:106:10
      |
  106 |     sys::set_errno(err)
      |          ^^^^^^^^^ not found in `sys`

  Some errors have detailed explanations: E0425, E0583.
  For more information about an error, try `rustc --explain E0425`.

default-features = false没有加;

  sp-io = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }

9. no method named using_encoded found for struct SignedPayload in the current scope

error[E0599]: no method named using_encoded found for struct SignedPayload in the current scope
–> /Users/xuanwenchao/Documents/projects/Rust/substrate/substrate-node-template/runtime/src/lib.rs:304:37
|
304 | let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?;
| ^^^^^^^^^^^^^ method not found in SignedPayload<RuntimeCall, (CheckNonZeroSender<Runtime>, CheckSpecVersion<Runtime>, CheckTxVersion<Runtime>, CheckGenesis<Runtime>, CheckMortality<Runtime>, CheckNonce<Runtime>, CheckWeight<Runtime>, ChargeTransactionPayment<Runtime>)>

该问题只需要runtime/src/lib.rs文件上方加:use codec::Encode;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xuanwenchao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值