cardano-serialization-lib icon indicating copy to clipboard operation
cardano-serialization-lib copied to clipboard

how to generate address of a plutus script

Open qichalerm opened this issue 2 years ago • 5 comments

hi, how to generate address of plutus script ?

Thanks.

qichalerm avatar Mar 21 '22 07:03 qichalerm

Hi,

You can get it using the cardano cli like this: cardano-cli address build --payment-script-file swap-testnet.plutus --testnet-magic 1097911063 --out-file swap-testnet.addr

ozgrakkurt avatar Mar 22 '22 02:03 ozgrakkurt

@vsubhuman Is there a way to get the address using serlib?

ozgrakkurt avatar Apr 04 '22 13:04 ozgrakkurt

Hi,

You can get it using the cardano cli like this: cardano-cli address build --payment-script-file swap-testnet.plutus --testnet-magic 1097911063 --out-file swap-testnet.addr

This question is obviously asking how to do it in serialization-lib considering that we are in the serialization-lib issues

grim-i-am avatar Apr 21 '22 09:04 grim-i-am

I think I got it working by doing the following:

  const wasm = await import('@emurgo/cardano-serialization-lib-nodejs');
  const script = cardano.PlutusScript.from_hex(contract.cborHex);
  const addr = cardano.EnterpriseAddress.new(
    0, // 0 for Testnet - 1 for Mainnet
    cardano.StakeCredential.from_scripthash(script.hash())
  );
  console.log( addr.to_address().to_bech32('addr_test') ); // Use appropriate prefix.

I seem to have matched up the resultant cardano-cli address doing it this way.

Note: I am on version 11.0.5 of @emurgo/cardano-serialization-lib-nodejs

gavinharris-dev avatar Sep 05 '22 03:09 gavinharris-dev

~~The above solution doesn't seem to work for me, I get a different address when using the Cardano CLI (cardano-cli address build --testnet-magic 1097911063 --payment-script-file validators/something.json)~~

{
    "type": "PlutusScriptV2",
    "description": "",
    "cborHex": "49480100002221200101"
}

~~Cardano CLI returns:~~

addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla

~~The solution above returns:~~

addr_test1wp3tms7sf5zrwm23d5ckvj2ykfww8tl6wmghlz67zfumf8gs6jh83

Nevermind, my script was a PlutusV2 script, so I had to use:

const script = PlutusScript.from_bytes_v2(fromHex(this.contract));

Can confirm that the solution above works for Plutus V2 too.

Displee avatar Jan 07 '23 15:01 Displee