Gka101
23 September 2022 13:56
1
Hello,
I am looking for help in how to get an address from a browser wallet, like typhon, nami, etrnl, or any other.
I have tried using the injected object, but I don’t see the address, ie:
// Already enabled the wallet
// Getting Used Addresses List
window.cardano.getUsedAddresses()
I get:
window.cardano.getUsedAddresses()
Promise {<pending>}
[[Prototype]]
:
Promise
[[PromiseState]]
:
"fulfilled"
[[PromiseResult]]
:
Array(1)
0
:
"003a9740ec9d23a0d956a19acea5aa6ecb87b2270a66b88620d12c03d3f92a07fd4c2b3450cda1e53c62233adbb7b9bba03ba4b2ffda5f332d"
length
:
1
[[Prototype]]
:
Array(0)
I am guessing a address is 003a9740ec9d23a0d956a19acea5aa6ecb87b2270a66b88620d12c03d3f92a07fd4c2b3450cda1e53c62233adbb7b9bba03ba4b2ffda5f332d
But don’t know how to decode this HexEncoded string? (just using JS or a npm package)
Thanks in advance for the help!!
Happy Coding!
Using https://github.com/Emurgo/cardano-serialization-lib :
"use strict"
const CSL = require("@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib")
const testnet_hex_address = Uint8Array.from(Buffer.from('003a9740ec9d23a0d956a19acea5aa6ecb87b2270a66b88620d12c03d3f92a07fd4c2b3450cda1e53c62233adbb7b9bba03ba4b2ffda5f332d', 'hex'))
const testnet_csl_address = CSL.Address.from_bytes(testnet_hex_address)
console.log(testnet_csl_address.to_bech32())
const mainnet_hex_address = Uint8Array.from(Buffer.from('0133726283b27928b20bb4baf0048d73027ae9f0b9fffd2c918f94a07359b8841a4c7b4b919ca88ef9132be58ee596cc6b3553f7477d4577b2', 'hex'))
const mainnet_csl_address = CSL.Address.from_bytes(mainnet_hex_address)
console.log(mainnet_csl_address.to_bech32())
According to https://github.com/cardano-foundation/CIPs/tree/master/CIP-0030#address , the wallet app should give you BECH32 directly and not hex. Which wallet app is it?
And by the way, using window.cardano.getUsedAddresses()
directly is deprecated: