2

I am trying to write a page to show all the transaction history of an account, I use StellarSdk.xdr.TransactionEnvelope.fromXDR(page.records[0].envelope_xdr, 'base64') to get the transaction envelope, however the source account is encoded with Ed25519.

I tried to use the function below to decode it, it will be shown as r��)'-�)�sjލC5�B }�'Z���?��.

function Decodeuint8arr(uint8array) {
    return new TextDecoder("utf8").decode(uint8array);
}

What is the correct way to decode the XDR information, thank you.

| improve this question | | | | |
1

It's a raw binary form of the public key. Use StrKey encoder to convert the binary key into the string representation:

import {StrKey} from 'stellar-sdk'

function formatPubKey(rawPubKey) {
  return StrKey.encodeEd25519PublicKey(rawPubKey)
}
| improve this answer | | | | |
  • Thank you a lot! Just a friendly reminder to the others, for calling the StrKey we could directly use StellarSdk.StrKey.encodeEd25519PublicKey(rawPubKey); – iDler May 18 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.