spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
341 stars 140 forks source link

Selecting correct wallet from CBOR Hex #112

Closed defiyass26 closed 1 year ago

defiyass26 commented 2 years ago

Hey Allessandro, I'm fairly new to development on Cardano...here's my issue...

I'm at my wits end here. Here's what I'm doing - I'm hoping you can set me straight...

import { Lucid, C } from 'lucid-cardano';

const lucid = await Lucid.new(new Blockfrost("https://cardano-mainnet.blockfrost.io/api/v0", PROJECT_ID, "Mainnet"));

// This is a demo CLI wallet.
const cborHex = "58209ccf4dc565bbcc400e09c7f9f4e20c31c7c411ac5692e7b045383d08def9ee5c";
const privateKey = C.PrivateKey.from_normal_bytes(Buffer.from(cborHex.substring(4), 'hex'));
const wallet = lucid.selectWalletFromPrivateKey(privateKey.to_bech32()).wallet;

console.log(wallet.address())
// Outputs: addr1vx7cef3rn0m0xtj4ps66h2tcqasme4m8l5fvs0ktg6802zgn0vjqp

console.log(wallet.getUtxos())
// Outputs: []

What am I doing wrong?

alessandrokonrad commented 2 years ago

I created a wallet on the CLI and funded it.

Did you create the wallet address without a stake key? Just to be sure here

defiyass26 commented 2 years ago

I'm not sure - the wallet address was generated through your CardanoCli package...I have a stake key if needed.

alessandrokonrad commented 2 years ago

I'm not sure - the wallet address was generated through your CardanoCli package...I have a stake key if needed

Is the address you generated with the CLI longer than addr1vx7cef3rn0m0xtj4ps66h2tcqasme4m8l5fvs0ktg6802zgn0vjqp?

defiyass26 commented 2 years ago

Yes.

// CLI wallet info
//
// payment addr: addr1qx7cef3rn0m0xtj4ps66h2tcqasme4m8l5fvs0ktg6802z25s4v95yucylgx3zqsmvdmk7jptzg2nztlgt24jf8cea4qlha987
// payment.sKey CBOR: 58209ccf4dc565bbcc400e09c7f9f4e20c31c7c411ac5692e7b045383d08def9ee5c
// payment.vKey CBOR: 5820a9e7345f7cd0d69f52b8ffc90160b87311e930bf021dba3b5ece950472d5566d
//
// stake addr: stake1u92g2kz6zwvz05rg3qgdkxam0fq43y9f39l5942eynuv76sls0z02
// stake.sKey CBOR: 582045abf0c4abd1dd5c4071ef4f81bea7fe202429e8a92fcc546e63b9b148ea7e27
// stake.vKey CBOR: 58207538fd682808f0bea3a7fdf8ed1381c93046c873322d9a6b61246e0f2ce16264
alessandrokonrad commented 2 years ago

Yeah the address you used in the CLI has a stake credential inside (Base address). The one you see in Lucid is an Enterprise address. It has the same payment credential, but there is no stake credential attached. Right now Lucid only gives you back UTxOs that match exactly that address even tho the payment credential may be the same. Maybe I'm gonna change that behaviour. Try to generate an Enterprise address in the CLI (without stake credential) and see if it matches: addr1vx7cef3rn0m0xtj4ps66h2tcqasme4m8l5fvs0ktg6802zgn0vjqp