0

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 with RUST_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 Answer 1

2

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) ✗ 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! that works for the home, but when i try to put it in a file like : /Users/Documents/Code/Thor/thor/parity/keys i get the following error: thread 'main' panicked at 'should load or generate new eth key: Error(SerdeJsonError(Error("Is a directory (os error 21)", line: 0, column: 0)), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })', src/libcore/result.rs:999:5 note: run with RUST_BACKTRACE=1` environment variable to display a backtrace` thanks for your help!
Looks like a new question :-). Your first question is a great minimal reproducible example. The comment, is really a brand new question. Please present it with its own minimal reproducible example in a new question, after accepting the answer in this question.
I have written a new question here: stackoverflow.com/questions/57201720/… thanks for your help!!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.