input-output-hk / js-cardano-wasm

various cardano javascript using wasm bindings
MIT License
31 stars 21 forks source link

How to connect to Byron #81

Closed kss-espeo closed 4 years ago

kss-espeo commented 4 years ago

Hi,

I am developing a simple, albeit custom Cardano wallet using NodeJS + Typescript. As advised by @SebastienGllmt I decided to use js-cardano-wasm to integrate with blockchain. For starters, I'd like to integrate with Byron testnet.

How do I connect to Byron instead of mainnet? Following your cardano-wallet example there is that BlockchainSettings class with its mainnet method. Digging through an implementation it seems this method provides ProtocolMagic with some arbitrary value (7648240731) which, I presume, represents mainnet. That's some magic indeed!

I'd imagine I need to use from_json method of BlockchainSettings to connect to Byron instead. Can I get some info on how to do this?

Thanks, KSS

SebastienGllmt commented 4 years ago

https://github.com/Emurgo/yoroi-frontend/blob/shelley/config/testnet.json

kss-espeo commented 4 years ago

Thanks for a quick reply, @SebastienGllmt .

I tried to connect to Byron like this: Cardano.BlockchainSettings.from_json({ "protocol_magic": 1097911063 }) .

Then I ran this example: https://github.com/input-output-hk/js-cardano-wasm/tree/master/cardano-wallet using mnemonics&password for an existing wallet that I created via REST API of a Byron Node. As a result I got an address which did not seem to be connected to that wallet, at least according to API&Daedalus. Please note that I have successfully interacted with this wallet using both REST API and Daedalus GUI in the past.

I have tried to, using Daedalus, send a transaction from another wallet to an address I got using previous step. Daedalus treated this address as a valid one. Indeed, my transaction was successfully executed but it was not send to an account connected to mnemonics&password used in previous step. Was I connected to Byron or not, then? If I was, why using mnemonics&password for an existing wallet didn't return its address?

On top of that, I changed Cardano.BlockchainSettings.from_json({ "protocol_magic": 1097911063 }) to Cardano.BlockchainSettings.from_json({ "protocol_magic": some_random_int }) . I would imagine that sample code would not execute since some_random_int does not represent any known network. However, it did and I got some address. Why did it work? Has it created some fake, stubbed network?

Does Cardano.BlockchainSettings.from_json({ "protocol_magic": 1097911063 }) indeed connect me to Byron? If so, does it use a local Cardano node or does it hit some remote Cardano node exposed as an open service?

SebastienGllmt commented 4 years ago

I can't speak to the Cardano node APi because I didn't work on that. You can generate an address with any protocol magic but only a few of them have actual networks for them. This is the Byron testnet explorer if you want to look for your transaction: https://cardano-explorer.cardano-testnet.iohkdev.io/

kss-espeo commented 4 years ago

Yeah, I can find it there. This means I was connected to Byron. I will try to play around with and try to figure out why Cardano.Bip44RootPrivateKey.recover hasn't retrieved an exisiting wallet but instead, apparently, created a new one.

Last question then. Sorry for asking so many. Can you please explain how ProtocolMagic works undercover? Does it use a local Cardano node or does it hit some remote Cardano node exposed as an open service?

SebastienGllmt commented 4 years ago

No protocol magic is just used to create addresses. Different protocol magic results in different addresses