问题
I am trying to use this crate to generate an ethereum address: https://docs.rs/ethkey/0.2.5/ethkey/
use ethkey::prelude::*;
fn main() {
let key = EthAccount::load_or_generate("~/", "passwd")
.expect("should load or generate new eth key");
println!("{:?}", key.address())
}
This is the example from the documentation and it doesnt seem to work. I get the error below:
cargo run Compiling ethkey v0.1.0 (/Users/samueldare/Documents/Code/Thor/ethkey) Finished dev [unoptimized + debuginfo] target(s) in 1.34s Running
target/debug/ethkey
thread 'main' panicked at 'should load or generate new eth key: Error(IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" }), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })', src/libcore/result.rs:999:5 note: run withRUST_BACKTRACE=1
environment variable to display a backtrace.
Ive use ~/
as a last attempt to generate the key file in rust, but it still doesnt seem to work.
I will appreciate any pointers with this
回答1:
The first argument to load_or_generate()
takes a std::path::Path with no closing slash ( '/' ). Remove the slash:
fn main() {
let key = EthAccount::load_or_generate("~", "passwd")
.expect("should load or generate new eth key");
println!("{:?}", key.address())
}
Sample output:
05:47 ethtest (master) ✗ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/ethtest`
Address(0x8248af6d1765e559509060b88e540a3567c42d20)
05:47 ethtest (master) ✗
来源:https://stackoverflow.com/questions/57201043/crate-cannot-find-path