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

Support to apply params to script

Open iTanChi opened this issue 1 year ago • 4 comments

In some cases, we need to pass the param to script at run time instead of build time to get the final script

Lucid lib supports this with rust lib: https://github.com/spacebudz/lucid/blob/457c156e74ef49ce35823aa2bca91b3bbc585221/src/core/libs/cardano_multiplatform_lib/src/tx_builder_utils.rs#L79C15-L79C15

#[wasm_bindgen]
pub fn apply_params_to_plutus_script(
    params: &PlutusList,
    plutus_script: PlutusScript,
) -> Result<PlutusScript, JsError> {
    match uplc::tx::apply_params_to_script(&params.to_bytes(), &plutus_script.bytes()) {
        Ok(res) => Ok(PlutusScript::new(res)),
        Err(err) => Err(JsError::from_str(&err.to_string())),
    }
}

iTanChi avatar Nov 29 '23 09:11 iTanChi

@iTanChi Parameterized contracts are already supported through aiken-java-binding library (0.0.8).

You can check these tests https://github.com/bloxbean/cardano-client-lib/blob/76496f51f458e0caa8f57758af738ec5bc740f6a/quicktx/src/it/java/com/bloxbean/cardano/client/quicktx/ParameterizedScriptIT.java#L116

satran004 avatar Nov 29 '23 14:11 satran004

Could this be done without aiken? I really want to use only this client lib instead of aiken lib

iTanChi avatar Nov 29 '23 15:11 iTanChi

@iTanChi Currently, there is no UPLC evaluator in pure Java. However, we are not using the Aiken programming language here. Instead, 'aiken-java-binding' utilizes a required library (through JNI) from Aiken to apply parameters to compiled code, so you don't need to add any additional dependencies.

I believe you don't need to write your contract in Aiken. You can simply use the compiled code from your contract (written in other languages like PlutusTx or Helios) and apply the parameters. I need to test this, but you can give it a try.

satran004 avatar Nov 30 '23 02:11 satran004

Fyi, Lucid JS also follows the same approach. It's using Aiken's rust library through wasm to support this feature.

satran004 avatar Nov 30 '23 02:11 satran004