<p>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.</p>
<p><a href="https://github.com/lley154/cardano-lottery/blob/main/src/Deploy.hs" rel="nofollow noreferrer">https://github.com/lley154/cardano-lottery/blob/main/src/Deploy.hs</a></p>
<p>Eg.</p>
<pre><code>txIdBS :: B.ByteString
txIdBS = &quot;aa604b873b89ea9e0f430e6c7b9af5d2bf426d88856eff97927e8469a196cdbd&quot;

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 -&gt; PlutusPrelude.BuiltinByteString
decodeHex hexBS =    
         case getTx of
            Right decHex -&gt; do
                --putStrLn $ &quot;Tx name: &quot; ++ show t
                PlutusPrelude.toBuiltin(decHex)  
            Left _ -&gt; do
                --putStrLn $ &quot;No Token name: &quot; ++ show e
                PlutusPrelude.emptyByteString 
                
        where        
            getTx :: Either String B.ByteString = B16.decode hexBS
</code></pre>

CC BY-SA 4.0
2022-09-09T00:00:10.663Z
2022-09-09T00:00:10.663Z
lley154
<p>Hello I want to convert a normal UTxO transaction hash to an encoded bytes string. How do I do this? Help would be appreciated!</p>
<p>something like</p>
<p><code>550665309dee7e2f64d13f999297f001763f65fe50bb05524afc0990c7dce0c3</code></p>
<p>to</p>
<p><code>828258205537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a8701825839016af9a0d2c9b5bce8999bc6430eb48f424399b73f0ecc143f40e8cac89b130cc3198a8594862fe25df331cb79447304dcd49712c86834fdf1821a00150bd0a1581cb0df0ee7dbb96b18b682a1091514f250eb0ec1122e6c4bf3b4d45123a14b436f6e766963743033363701</code></p>

CC BY-SA 4.0
2022-09-08T23:54:22.243Z
I don't understand. The first string you provides is hex encoded.
Erik de Castro Lopo
CC BY-SA 4.0
2022-09-13T04:31:40.100Z
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
<cardano-cli><cardano-serialization-lib><nami-wallet><cardano-address>
Convert UTxO to hex encoded bytes string
# Convert UTxO to hex encoded bytes string

(Asked by: username_0 on 2022-09-08)

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`

**Tags:** cardano-cli, cardano-serialization-lib, nami-wallet, cardano-address
> **Comments:**
> **username_1**: I don't understand. The first string you provides is hex encoded.  
> **username_2**: 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  

---

## 1 answers

### Answer by username_3 on 2022-09-09. Score: 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


---

