How do I generate zcash wallets in the Rust Programming Language?

Trying to generate zcash wallets for users on my app. I’m not an experienced programmer & just generally need help with the code.
Open ai gave me this earlier.

use zcash_primitives::legacy::TransparentAddress;
use zcash_primitives::zip32::{ExtendedFullViewingKey, ExtendedSpendingKey};

fn main() {
    let extsk = ExtendedSpendingKey::master(&[0u8; 32]);
    let extfvk = ExtendedFullViewingKey::from(extsk);
    let (diversifier_index, payment_address) = extfvk.default_address();
    let address = TransparentAddress::from(payment_address);
    println!("Zcash address: {:?}", address);
}

I have the following error message error[E0308]: mismatched types `` --> src/main.rs:6:47 | 6 | let extfvk = ExtendedFullViewingKey::from(extsk); | ---------------------------- ^^^^^ expected struct ExtendedFullViewingKey, found struct ExtendedSpendingKey`
| |
| arguments to this function are incorrect
|
note: associated function defined here
→ /home/developer/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:548:8
|
548 | fn from(value: T) → Self;
| ^^^^

error[E0308]: mismatched types
→ src/main.rs:8:44
|
8 | let address = TransparentAddress::from(payment_address);
| ------------------------ ^^^^^^^^^^^^^^^ expected enum TransparentAddress, found struct PaymentAddress
| |
| arguments to this function are incorrect``

dont think Open AI understands Zcash code yet
but presonally not a prigrammer

I would guess that youre probably lacking some crate dependency with an implementation for conversion between those types but not sure

Not bad at all for… AI is getting scarily good.

  • It’s missing the & in the from SK to FVK
  • it’s using a transparent address cast when it should be encoding the payment address to a string. That part shows it doesn’t see the relationships between the SK, FVK & z-address.
use zcash_client_backend::encoding::encode_payment_address;
use zcash_primitives::consensus::Network::MainNetwork;
use zcash_primitives::consensus::Parameters;
use zcash_primitives::zip32::{ExtendedFullViewingKey, ExtendedSpendingKey};

fn main() {
    let extsk = ExtendedSpendingKey::master(&[0u8; 32]);
    let extfvk = ExtendedFullViewingKey::from(&extsk);
    let (_, payment_address) = extfvk.default_address();
    let address =
        encode_payment_address(MainNetwork.hrp_sapling_payment_address(), &payment_address);
    println!("Zcash address: {:?}", address);
}
5 Likes

Thanks! But I still got the following error.
cargo run

   --> src/main.rs:8:47
    |
8   |     let extfvk = ExtendedFullViewingKey::from(&extsk);
    |                  ---------------------------- ^^^^^^ expected struct `ExtendedFullViewingKey`, found `&ExtendedSpendingKey`
    |                  |
    |                  arguments to this function are incorrect
    |
note: associated function defined here
   --> /home/developer/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:548:8
    |
548 |     fn from(value: T) -> Self;
    |        ^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `forum` due to previous error ```

We don’t use the same version of librustzcash then.

From the discord, I assume from the same user

Never mind just read the documentation on orchard at docs.rs ``` use orchard::keys::{SpendingKey, FullViewingKey, Scope};

let sk = SpendingKey::from_bytes([7; 32]).unwrap();
let address = FullViewingKey::from(&sk).address_at(0u32, Scope::External);

I think that “Artificial Intelligence” sounds pejorative. I prefer “Silicon Substrate Consciousness” (SSC), or just SC. I believe that SC is just as natural as Carbon Substrate Consciousness (CSS)… or…

Depending on your cosmology, we can just say that CSS is plausibly just as “Artificial”…

In either case the term AI is antiquated… (like the term “privacy”), and should be revised.

Why is this relevant here? Because I don’t assume that I know @william2 's hardware base composition (silicon vs carbon).

Indeed, the pejorative language in this thread brought my laptop to tears. He announced that he’s taking the rest of day off to regain his composure and then promptly shut down. (Posting this from my phone.)

Actual Laugh Out Loud… or… as the hipsters say: ALOL

Please do not consider the set of words that rhyme with ALOL.

NOOOOOOOO… I said DON’T think about the rhymes!