cardano-client-lib
cardano-client-lib copied to clipboard
Exunits purpose in contracts
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
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