首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何导入substrate_primitives以便使用sr25519?

如何导入substrate_primitives以便使用sr25519?
EN

Stack Overflow用户
提问于 2020-02-28 20:31:00
回答 1查看 206关注 0票数 2

我的Cargo.toml文件中有以下依赖项:

代码语言:javascript
复制
[package]
name = "api-client-tutorial"
version = "0.1.0"
authors = ["Supercomputing Systems AG <info@scs.ch>"]
edition = "2018"

[dependencies]
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git" }
codec = { package = "parity-scale-codec", features = ["derive"], version = "1.0.0", default-features = false }

[dependencies.primitives]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-primitives"

[dependencies.keyring]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-keyring"

我不确定dependencies节和dependencies.primitives节之间的区别,但是包substrate-primitives包含在原语部分中。

见过 substrate_primitives有我需要使用的模块sr25519,但是当我试图在代码中导入它时:

代码语言:javascript
复制
use substrate_api_client::{Api, node_metadata};
use substrate_primitives::sr25519;
fn main() {
    // instantiate an Api that connects to the given address
    let url = "127.0.0.1:9944";
    // if no signer is set in the whole program, we need to give to Api a specific type instead of an associated type
    // as during compilation the type needs to be defined.
    let api = Api::<sr25519::Pair>::new(format!("ws://{}", url));

    let meta = api.get_metadata();
    println!("Metadata:\n {}", node_metadata::pretty_format(&meta).unwrap());
}

我得到以下错误:

代码语言:javascript
复制
unresolved import `substrate_primitives`

use of undeclared type or module `substrate_primitives`rustc(E0432)
main.rs(2, 5): use of undeclared type or module `substrate_primitives`

如何导入sr25519,以便在代码中使用以下行?

代码语言:javascript
复制
let api = Api::<sr25519::Pair>::new(format!("ws://{}", url));
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-01 09:49:19

[dependencies]下的表与[dependencies.primitives]表下的表之间的区别是,primitives依赖项的表没有内联。您还可以内联primitives依赖项,并将其放在[dependencies]下,如下所示:

代码语言:javascript
复制
primitives = { git = "https://github.com/paritytech/substrate", rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5", package = "substrate-primitives" }

toml文档可以为您提供有关表和内联表的更多详细信息。

关于你的问题。您不能像这样导入机箱,因为它被重命名为primitivespackage字段指定依赖项的实名,表名定义用于在项目中导入它的新名称。有关详细信息,请看一下货物单据

因此,您的导入应该如下所示:use primitives::sr25519;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60458851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档