CityOfZion / neon-js

Javascript libraries that allow the applications to interact with NEO blockchain
https://docs.coz.io/neo3/neon-js/index.html
MIT License
183 stars 165 forks source link

How to convert a Base64 script hash to Neo 3 address using neon-js? #894

Closed robliou closed 1 year ago

robliou commented 1 year ago

Hello!

As the title states, I'm trying to convert a Base64 script hash to Neo3 address (wallet), but am getting the error:

caught (in promise) TypeError: _cityofzion_neon_js__WEBPACK_IMPORTED_MODULE_1___default(...).getAddressFromScriptHash is not a function at base64ToAddress (bundle.js:846:70) at bundle.js:853:56 at Array.map (<anonymous>) at bundle.js:831:40

To perform this conversion, I am referencing the NeonJS documentation. My code looks like this:

let sender = 'awgi2P8/4E++jPhMsWZ1ST7o9FRVI='

const base64ToAddress = function (sender) {
              wallet.getAddressFromScriptHash(base64ToHash160(sender));
            };

            const base64ToHash160 = function (sender) {
              u.reverseHex(u.base642hex(sender));
            };

console.log('this is base64ToAddress', base64ToAddress)

What could I be doing wrong here?

Thanks in advance,

ixje commented 1 year ago

There are multiple problems here

  1. your base64ToHash160 doesn't return anything
  2. your base64ToHash160 is used before it's defined
  3. you're not using base64ToAddress correctly when logging (you're not supplying any arguments)
  4. your error for the most part does not seem to align with the code that you posted

I'm closing this as this is not an issue with neon-js but with understanding TS.

When reporting possible issues in the future, please include reproducible code snippet so it's easier to assist.