Base 58 check through aesdk-js failed on contract address with front-end

Hello everyone,

I am using aesdk on front-end framework. If I create a contract instance then I receive an Invalid contract address error. I tried with multiple addresses, networks etc. but after instance is successfully created and connected with superhero wallet, I always get contract address error.

I looked in aesdk library from node_modules and found the spot where it creates error, Which is inside crypto.js file which checks for Base58 address by try to decode it which creates an error to move to catch block and return false. However after bs58check, I looked for libraries etc to debug it.

So now → The address without prefix which is ct passes as string on base58check decode function like this 2r3Zn9gLJvsN8W4wD6YekPsvMrb7rESMTFLVg6QvjJpFXbph37 but it returns false in the below function .

Which causes throw that error and not moving to step 16

After using different base58 check libraries, I check online as well but it

Let me know if additional details require.

It sure looks 25 bytes but why it says invalid and no base58check library decode returns a value.

Does it work for you to do this in aestudio ? E.g.

  1. deploy contract
  2. copy its address
  3. delete the deployed contract from the sidebar on the right
  4. paste the address in the “at address” field on the right an click the “at address” button
  5. call some non-stateful function to test talking to the contract

Yes nick, it does works on Ae studio.

Please Note: I am using node polyfill because of webpack5 otherwise it doesn’t resolve crypto module.

1 Like
([email protected])1> aeser_api_encoder:decode(<<"ct_2r3Zn9gLJvsN8W4wD6YekPsvMrb7rESMTFLVg6QvjJpFXbph37">>).
{contract_pubkey,<<243,14,152,80,189,150,53,182,100,248,
                   197,48,11,133,50,209,62,165,2,65,15,
                   42,96,250,16,241,42,219,34,112,42,121>>}

Indeed it is a valid æternity contract address. Since æternity and Bitcoin uses different elliptic curves, and also different address representations (Bitcoin has short 20 + 5 byte addresses) it is hardly surprising that it doesn’t pass a Bitcoin validator.

And no it isn’t 25 bytes it is 36 bytes - 32 bytes is the address and 4 bytes are the checksum. The first hit when I google “base58check decode online” namely this converter correctly decodes your input 2r3Zn9gLJvsN8W4wD6YekPsvMrb7rESMTFLVg6QvjJpFXbph37 into f30e9850bd9635b664f8c5300b8532d13ea502410f2a60fa10f12adb22702a7978401652

So with that sorted, what was the question, I got distracted by all the incorrect nonsense in the thread so far?!

5 Likes

I think it’s simply that the SDK’s method is failing for him @hanssv.chain , for some reason.

Tried to recreate the issue using aepp-sdk-js
It’s a valid address

Crypto.isAddressValid(“ct_2r3Zn9gLJvsN8W4wD6YekPsvMrb7rESMTFLVg6QvjJpFXbph37”, “ct”)
true

1 Like

Then perhaps simply tagging it with SDK would be a good idea (instead or oracles as it was tagged with initially)?!

Crypto.isAddressValid(“ct_2r3Zn9gLJvsN8W4wD6YekPsvMrb7rESMTFLVg6QvjJpFXbph37”, “ct”)

This method takes only one argument. Can you please confirm that you typed it correct ?

Yes, that would be better.

@nikitafuchs.chain I try to bypass the library for now. But I should mention that it seems to be a very careful issue. Because it is just gonna increase my work. ( I do rm -rf and npm i many times) I like to see them installing :slight_smile: .

This converter decodes anything

It was about aesdk-js library which I am using with polyfill to run crypto functions on the front-end.
For some logical reason, It works on backend, but not on front-end: creating issue from that specific function.

Using noble-base58check I can decode it on front-end as well, But it is not working from me from crypto library as i tried, because it output it as async operation which bs58-check suppose to do it in sync however even trying it seperately, It doesn’t work with the bundler I use. It looks like the one that @nikitafuchs.chain uses currently may have some issues with >= webpack5.

I’ve helped with the correct label then… Maybe you can get it right from the start next time :+1:

3 Likes

Thank you @hanssv.chain .

If you are using the latest published version, I see the method taking 2 params

The default prefix is ak but in your case it should be ct

1 Like

Thank you for sharing.