Evolution SDK
Smart contracts

Locking to Script

Send funds to a script address with datums

Locking to Script

Locking funds to a script means sending ADA or native tokens to a script address with a datum attached. The datum carries the state your validator will check when someone tries to spend the UTxO later.

This is the first half of any smart contract interaction — you lock funds, then later spend them.

Basic Lock

Send ADA to a script address with an inline datum:

import { , , , ,  } from "@evolution-sdk/evolution"

const  = ({
  : "preprod",
  : { : "blockfrost", : "https://cardano-preprod.blockfrost.io/api/v0", : ..! },
  : { : "seed", : ..!, : 0 }
})

const  = .(
  "addr_test1wrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qnmqsyu"
)

const  = await 
  .()
  .({
    : ,
    : .(10_000_000n), // 10 ADA
    : new .({ : .(0n, []) })
  })
  .()

const  = await .()
const  = await .()
.("Locked funds at:", )

Lock with Structured Datum

For real contracts, define your datum with TSchema for type safety:

import { , , , , , ,  } from "@evolution-sdk/evolution"

const  = ({
  : "preprod",
  : { : "blockfrost", : "https://cardano-preprod.blockfrost.io/api/v0", : ..! },
  : { : "seed", : ..!, : 0 }
})

// Define escrow datum schema
const  = .({
  : .,
  : .,
  : .
})

const  = .()

// Create datum
const  = .({
  : .("abc123def456abc123def456abc123def456abc123def456abc123de"),
  : 1735689600000n,
  : 25_000_000n
})

const  = .(
  "addr_test1wrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qnmqsyu"
)

const  = await 
  .()
  .({
    : ,
    : .(25_000_000n),
    : new .({ :  })
  })
  .()

const  = await .()
const  = await .()

Lock with Native Tokens

Lock both ADA and native tokens to a script:

import { , , , ,  } from "@evolution-sdk/evolution"

const  = ({
  : "preprod",
  : { : "blockfrost", : "https://cardano-preprod.blockfrost.io/api/v0", : ..! },
  : { : "seed", : ..!, : 0 }
})

const  = .(
  "addr_test1wrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qnmqsyu"
)

// Create assets with ADA + tokens
let  = .(5_000_000n)
 = .(
  ,
  "7edb7a2d9fbc4d2a68e4c9e9d3d7a5c8f2d1e9f8a7b6c5d4e3f2a1b0c9d8e7f6",
  "",
  100n
)

const  = await 
  .()
  .({
    : ,
    ,
    : new .({ : .(0n, [100n]) })
  })
  .()

const  = await .()
await .()

Lock with Reference Script

Store a script on-chain alongside the locked funds. Other transactions can reference this script instead of including it directly:

import { , , , ,  } from "@evolution-sdk/evolution"

const  = ({
  : "preprod",
  : { : "blockfrost", : "https://cardano-preprod.blockfrost.io/api/v0", : ..! },
  : { : "seed", : ..!, : 0 }
})

declare const : any

const  = .(
  "addr_test1wrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qnmqsyu"
)

const  = await 
  .()
  .({
    : ,
    : .(10_000_000n),
    : new .({ : .(0n, []) }),
    :  // Store script in UTxO for reference
  })
  .()

const  = await .()
await .()

Multiple Locks in One Transaction

Lock funds to multiple script addresses in a single transaction:

import { , , , ,  } from "@evolution-sdk/evolution"

const  = ({
  : "preprod",
  : { : "blockfrost", : "https://cardano-preprod.blockfrost.io/api/v0", : ..! },
  : { : "seed", : ..!, : 0 }
})

const  = .("addr_test1wrm9x2dgvdau8vckj4duc89m638t8djmluqw5pdrFollw8qnmqsyu")
const  = .("addr_test1wz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3pqsyu")

const  = await 
  .()
  .({
    : ,
    : .(10_000_000n),
    : new .({ : .(0n, [1735689600000n]) })
  })
  .({
    : ,
    : .(50_000_000n),
    : new .({ : .(0n, [1735776000000n, 5000000n]) })
  })
  .()

const  = await .()
await .()

Next Steps