<p>In lieu of up-to-date documentation, the best approach is to look at how current projects are using the library. E.g. <a href="https://github.com/Berry-Pool/nami-wallet/blob/main/src/api/extension/index.js" rel="nofollow noreferrer">https://github.com/Berry-Pool/nami-wallet/blob/main/src/api/extension/index.js</a></p>

CC BY-SA 4.0
2022-07-18T16:53:02.297Z
Thanks for the attention. Feel free to edit your comment into an answer and I'll be happy to upvote
irth
CC BY-SA 4.0
2022-07-15T08:28:40.927Z
2022-07-25T10:47:56.080Z
2022-07-25T10:47:56.080Z
james
<p>I'm trying to get cardano-serialization-lib working without up-to-date docs (<a href="https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-transactions.md" rel="nofollow noreferrer">https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-transactions.md</a>). The example for making a transaction is outdated and the method .from_bech() doesn't exist on PrivateKey property.</p>
<p>Since the txBuilder.add_key_input() function is expecting an ed25519 hash, i thought it could be good to use Ed25519KeyHash but I am getting rust errors somewhere in the wasm hand-off.</p>
<p>Can anyone explain how to generate a root key and properly pass into the txBuilder.add_key_input() function?</p>
<p>Ultimately my goal to to generate and sign transactions from javascript without running a node and sync'd wallet. Any suggestions are welcome comments.</p>
<pre><code>const cardano = (async () =&gt; { return await import('@emurgo/cardano-serialization-lib-browser') })()

let cw = cardano.then(async x =&gt; {
  console.log(x, x.Bip32PrivateKey); 
  function harden(num) {
    return 0x80000000 + num;
  }
  
  const rootKey = x.Bip32PrivateKey.from_bech32(&quot;xprv17qx9vxm6060qjn5fgazfue9nwyf448w7upk60c3epln82vumg9r9kxzsud9uv5rfscxp382j2aku254zj3qfx9fx39t6hjwtmwq85uunsd8x0st3j66lzf5yn30hwq5n75zeuplepx8vxc502txx09ygjgx06n0p&quot;);
  
  const accountKey = rootKey
    .derive(harden(1852)) // purpose
    .derive(harden(1815)) // coin type
    .derive(harden(0)); // account #0
  
  const utxoPubKey = accountKey
    .derive(0) // external
    .derive(0)
    .to_public();
  
  const stakeKey = accountKey
    .derive(2) // chimeric
    .derive(0)
    .to_public();
  
  console.log({ rootKey, accountKey, utxoPubKey, stakeKey })
  console.log(rootKey, x.PrivateKey.generate_ed25519(accountKey))


  const txBuilder = x.TransactionBuilder.new(
    // all of these are taken from the mainnet genesis settings
    // linear fee parameters (a*size + b)
    x.LinearFee.new(x.BigNum.from_str('44'), x.BigNum.from_str('155381')),
    // minimum utxo value
    x.BigNum.from_str('1000000'),
    // pool deposit
    x.BigNum.from_str('500000000'),
    // key deposit
    x.BigNum.from_str('2000000')
);
// const prvKey = x.PrivateKey.from_bech32(&quot;ed25519e_sk16rl5fqqf4mg27syjzjrq8h3vq44jnnv52mvyzdttldszjj7a64xtmjwgjtfy25lu0xmv40306lj9pcqpa6slry9eh3mtlqvfjz93vuq0grl80&quot;);
txBuilder.add_key_input(
    new x.Ed25519KeyHash(rootKey),
    x.TransactionInput.new(
        x.TransactionHash.from_bytes(
            Buffer.from(&quot;8561258e210352fba2ac0488afed67b3427a27ccf1d41ec030c98a8199bc22ec&quot;, &quot;hex&quot;)
        ), // tx hash
        0, // index
    ),
    x.Value.new(x.BigNum.from_str('3000000'))
);
  console.log({txBuilder});
  return x
})```


  [1]: https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-transactions.md
</code></pre>

<trust>
Cardano Serialization: How does Ed25519KeyHash work
# Cardano Serialization: How does Ed25519KeyHash work

(Asked by: username_0 on 2021-10-31)

I'm trying to get cardano-serialization-lib working without up-to-date docs (https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-transactions.md). The example for making a transaction is outdated and the method .from_bech() doesn't exist on PrivateKey property.
Since the txBuilder.add_key_input() function is expecting an ed25519 hash, i thought it could be good to use Ed25519KeyHash but I am getting rust errors somewhere in the wasm hand-off.
Can anyone explain how to generate a root key and properly pass into the txBuilder.add_key_input() function?
Ultimately my goal to to generate and sign transactions from javascript without running a node and sync'd wallet. Any suggestions are welcome comments.
const cardano = (async () => { return await import('@emurgo/cardano-serialization-lib-browser') })()

let cw = cardano.then(async x => {
  console.log(x, x.Bip32PrivateKey); 
  function harden(num) {
    return 0x80000000 + num;
  }
  
  const rootKey = x.Bip32PrivateKey.from_bech32("xprv17qx9vxm6060qjn5fgazfue9nwyf448w7upk60c3epln82vumg9r9kxzsud9uv5rfscxp382j2aku254zj3qfx9fx39t6hjwtmwq85uunsd8x0st3j66lzf5yn30hwq5n75zeuplepx8vxc502txx09ygjgx06n0p");
  
  const accountKey = rootKey
    .derive(harden(1852)) // purpose
    .derive(harden(1815)) // coin type
    .derive(harden(0)); // account #0
  
  const utxoPubKey = accountKey
    .derive(0) // external
    .derive(0)
    .to_public();
  
  const stakeKey = accountKey
    .derive(2) // chimeric
    .derive(0)
    .to_public();
  
  console.log({ rootKey, accountKey, utxoPubKey, stakeKey })
  console.log(rootKey, x.PrivateKey.generate_ed25519(accountKey))


  const txBuilder = x.TransactionBuilder.new(
    // all of these are taken from the mainnet genesis settings
    // linear fee parameters (a*size + b)
    x.LinearFee.new(x.BigNum.from_str('44'), x.BigNum.from_str('155381')),
    // minimum utxo value
    x.BigNum.from_str('1000000'),
    // pool deposit
    x.BigNum.from_str('500000000'),
    // key deposit
    x.BigNum.from_str('2000000')
);
// const prvKey = x.PrivateKey.from_bech32("ed25519e_sk16rl5fqqf4mg27syjzjrq8h3vq44jnnv52mvyzdttldszjj7a64xtmjwgjtfy25lu0xmv40306lj9pcqpa6slry9eh3mtlqvfjz93vuq0grl80");
txBuilder.add_key_input(
    new x.Ed25519KeyHash(rootKey),
    x.TransactionInput.new(
        x.TransactionHash.from_bytes(
            Buffer.from("8561258e210352fba2ac0488afed67b3427a27ccf1d41ec030c98a8199bc22ec", "hex")
        ), // tx hash
        0, // index
    ),
    x.Value.new(x.BigNum.from_str('3000000'))
);
  console.log({txBuilder});
  return x
})```


  [1]: https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-transactions.md

**Tags:** trust

---

## 1 answers

### Answer by username_1 on 2022-07-15. Score: 1

In lieu of up-to-date documentation, the best approach is to look at how current projects are using the library. E.g. <https://github.com/Berry-Pool/nami-wallet/blob/main/src/api/extension/index.js>

> **Comments:**
> **username_0**: Thanks for the attention. Feel free to edit your comment into an answer and I'll be happy to upvote  

---

