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

Exunits purpose in contracts

Open ofekron33 opened this issue 2 years ago • 1 comments

hey, i have a quick question. i am looking at the example guess contract you have here: https://github.com/bloxbean/cardano-client-examples/blob/main/src/main/java/com/bloxbean/cardano/client/examples/function/contract/CustomGuessContractTest.java

and i dont understand what is the purpose of the Exunits. if you could explain it to me or if you have other resource online that explains it because i tried to look and couldnt find anything.

Thanks.

ofekron33 avatar Apr 24 '22 10:04 ofekron33

@ofekron33

ExUnits is used to calculate script running cost which gets added to the transaction fee. ExUnits consists of steps (cpu time) and mem (RAM space).

You can check this page for more detail https://playground.plutus.iohkdev.io/doc/plutus/howtos/analysing-scripts.html

You can also check "Plutus fee Estimator" tool from IOG. https://docs.cardano.org/plutus/Plutus-tools

Ideally, you need to calculate ExUnits for a script in runtime as it may change based on inputs / redeemers. The following example shows how to do that

https://github.com/bloxbean/cardano-client-lib/blob/0ac220b69164a5305c71afefa7784f116ef9a1e1/integration-test/src/it/java/com/bloxbean/cardano/client/function/ContractTxBuilderContextITTest.java#L158

satran004 avatar Apr 24 '22 12:04 satran004