cardano-serialization-lib
cardano-serialization-lib copied to clipboard
how to generate address of a plutus script
hi, how to generate address of plutus script ?
Thanks.
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
@vsubhuman Is there a way to get the address using serlib?
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
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
~~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.