1

In plutus endpoint, I want to convert Address type value to get addr_testXXX format address.

I have try :

import Cardano.Api  ( SerialiseAddress (deserialiseAddress, serialiseAddress) )
  ...
-- here, var 'testAddr' is of 'Address' type
printf "ledger address is: %s"  $ show $ serialiseAddress testAddr

but it raised error when compiling:

    • No instance for (SerialiseAddress
                         plutus-ledger-api-0.1.0.0:Plutus.V1.Ledger.Address.Address)
        arising from a use of ‘serialiseAddress’

From google, I found this: https://github.com/functionally/mantis/blob/1cd121202452dcc1bce56ed4b4f41f0e880c9d04/src/Mantra/Wallet.hs#L56 It seem that I should convert Address to AddressAny, but don't know how to.

Any help will be appreciated!

2

1 Answer 1

0

Here is a demo in Java:

public String swapAddress(String address) {
    byte[] bech = Bech32.decode(address).data;
    byte[] conv = Utils.convertBits(bech, 5, 8, false);
    conv = Bytes.sub(conv, 0, conv.length - 1);
    int networkId = conv[0] & 0x0F;
    String hrp = "";
    if (networkId == 0) {
        hrp = "addr";
        networkId = 1;
    } else {
        hrp = "addr_test";
        networkId = 0;
    }
    conv[0] = ((byte) networkId);
    byte[] data = Utils.convertBits(conv);
    return Bech32.encode(hrp, data);
}

You can find the convertBits here and Bech32 here. For Cardano, Bech32 #152 & #153 are unnecessary.

1
  • Thanks for your kindly help. But I write plutus code and looking forward to haskell example. Jul 1 at 9:24

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.