I'm converting IPFS multi hash to hex, and after throwing away its prefix I want to attach that hash to a stellar transaction (something like here). I build it this way:

let transaction = new StellarSdk.TransactionBuilder(account)
        destination: supply,
        asset: StellarSdk.Asset.native(),
        amount: MIN,

At runtime let's say the hash value is:


But after consensus has been reached, I retrieve the same transaction and it shows a different value for the memo hash:

memo: "jDOeFb2J5/jH1sdUuAFqICu6EqjNtKq+OcbJ4wUHqPM="
memo_type: "hash"



While I'm not sure why this happens, this is not a different hash, its just encoded in base64

   >>> import base64
   >>> base64.b64decode('jDOeFb2J5/jH1sdUuAFqICu6EqjNtKq+OcbJ4wUHqPM=').hex()
  • I'm doing it like this bs58.decode(multiHash).slice(2).toString('hex'); and get the hex string, this is strange Jul 21 '18 at 17:05
  • Base64 encoding is what is used to store the data on the blockchain as it is more compact. In most cases, in js-stellar-sdk, the values are stored as buffer. You can get back to hex using something like buffer.toString('hex') Jul 21 '18 at 18:40
  • 1
    @MisterTicot What's stored on the blockchain is the actual 256-bit binary string. Base64 encoding is just used as a representation to get printable characters. Jul 22 '18 at 1:36
  • 2
    Ok after retrieving the memo hash it is sufficient to do this let buffer = Buffer.from(txs[0].memo, 'base64'); let string = buffer.toString('hex'); Jul 22 '18 at 9:09
  • 1
    @JohanStén Of course you're right. Thank you for the correction. Jul 23 '18 at 3:00

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.