whisky
Github
  • whisky
  • WASM - whisky-js
  • Tx Builder
    • Getting Started
      • Lock Fund
      • Unlock Fund
      • Mint Tokens
      • Delegate Stake
      • Complex Transaction
    • Service Integration
  • Services
    • Providers
      • Fetcher
      • Evaluator
      • Submitter
Powered by GitBook
On this page
  1. Tx Builder
  2. Getting Started

Lock Fund

Build a transaction to send funds to a smart contract

The following shows a simple example of building a transaction to lock fund in a smart contact.

use whisky::*;

pub fn lock_fund(
    script_address: &str,
    datum: &str,
    my_address: &str,
    inputs: &[UTxO],
) -> Result<String, WError> {
    let mut tx_builder = TxBuilder::new_core();
    tx_builder
        .tx_out(script_address, &[])
        .tx_out_inline_datum_value(&WData::JSON(datum.to_string())) // JSON string datum
        // .tx_out_datum_hash_value(WData::JSON(datum.to_string())) // Datum hash
        .change_address(my_address)
        .select_utxos_from(inputs, 5000000)
        .complete_sync(None)?;

    Ok(tx_builder.tx_hex())
}

PreviousGetting StartedNextUnlock Fund

Last updated 1 month ago