0

Hello I want to convert a normal UTxO transaction hash to an encoded bytes string. How do I do this? Help would be appreciated!

something like

550665309dee7e2f64d13f999297f001763f65fe50bb05524afc0990c7dce0c3

to

828258205537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a8701825839016af9a0d2c9b5bce8999bc6430eb48f424399b73f0ecc143f40e8cac89b130cc3198a8594862fe25df331cb79447304dcd49712c86834fdf1821a00150bd0a1581cb0df0ee7dbb96b18b682a1091514f250eb0ec1122e6c4bf3b4d45123a14b436f6e766963743033363701

2
  • I don't understand. The first string you provides is hex encoded. Sep 8, 2022 at 23:54
  • Would be helpful to also share why you trying to do this and what is your final goal. This way someone can provide different types of solution related to your question
    – Nic_T2H
    Sep 13, 2022 at 4:31

1 Answer 1

0

I think what you are asking is how to convert from base 16 to base 10 which is how a bytestring is stored on the blockchain. You can take a look at my Deploy.hs code which does this conversion.

https://github.com/lley154/cardano-lottery/blob/main/src/Deploy.hs

Eg.

txIdBS :: B.ByteString
txIdBS = "aa604b873b89ea9e0f430e6c7b9af5d2bf426d88856eff97927e8469a196cdbd"

let some_val = $ decodeHex txIdBS 

-- | Decode from hex base 16 to a base 10 bytestring is needed because
--   that is how it is stored in the ledger onchain
where

decodeHex :: B.ByteString -> PlutusPrelude.BuiltinByteString
decodeHex hexBS =    
         case getTx of
            Right decHex -> do
                --putStrLn $ "Tx name: " ++ show t
                PlutusPrelude.toBuiltin(decHex)  
            Left _ -> do
                --putStrLn $ "No Token name: " ++ show e
                PlutusPrelude.emptyByteString 
                
        where        
            getTx :: Either String B.ByteString = B16.decode hexBS

Your Answer

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

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