7

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)
    .addOperation(StellarSdk.Operation.payment({
        destination: supply,
        asset: StellarSdk.Asset.native(),
        amount: MIN,
    }))
    .addMemo(StellarSdk.Memo.hash(hash))
    .build();
transaction.sign(pair);

At runtime let's say the hash value is:

8c339e15bd89e7f8c7d6c754b8016a202bba12a8cdb4aabe39c6c9e30507a8f3

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"

Why?

9

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()
   '8c339e15bd89e7f8c7d6c754b8016a202bba12a8cdb4aabe39c6c9e30507a8f3'
  • I'm doing it like this bs58.decode(multiHash).slice(2).toString('hex'); and get the hex string, this is strange – Maxim Gaina 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') – Mister Ticot Jul 21 '18 at 18:40
  • @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. – Johan Stén Jul 22 '18 at 1:36
  • 1
    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'); – Maxim Gaina Jul 22 '18 at 9:09
  • @JohanStén Of course you're right. Thank you for the correction. – Mister Ticot 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.