3

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.

1 Answer 1

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)
}
1
  • 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, 2020 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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