Plutus Examples
Vesting Example
party Owner;party Beneficiary;
policy TimeLock = 0x6b9c456aa650cb808a9ab54326e039d5235ed69f069c9664a8fe5b69;
type State { lock_until: Int, owner: Bytes, beneficiary: Bytes,}
tx lock( quantity: Int, until: Int) { input source { from: Owner, min_amount: Ada(quantity), }
output target { to: TimeLock, amount: Ada(quantity), datum: State { lock_until: until, owner: Owner, beneficiary: Beneficiary, }, }
output { to: Owner, amount: source - Ada(quantity) - fees, }}
tx unlock( locked_utxo: UtxoRef) { input gas { from: Beneficiary, min_amount: fees, }
input locked { from: TimeLock, ref: locked_utxo, redeemer: (), }
output target { to: Beneficiary, amount: gas + locked - fees, }}
Order-book Example
party Sender;party Receiver;
// Always true plutus v2policy OrderBook = 0x39c520d0627aafa728f7e4dd10142b77c257813c36f57e2cb88f72a5;
// Policy always trueasset ControlToken = 0x13a0e59ca61ab277e909ffd20def27d296051fbc634cf623c02322a5.CONTROL;asset Ask = 0x13a0e59ca61ab277e909ffd20def27d296051fbc634cf623c02322a5.ASK;asset Bid = 0x13a0e59ca61ab277e909ffd20def27d296051fbc634cf623c02322a5.BID;
type AssetClass { policy: Bytes, name: Bytes,}
type DatumValue { asset_class: AssetClass, amount: Int,}
type OrderInfo { sender_address: Bytes, token: DatumValue,}
type OrderDatum { info: OrderInfo, control_asset_class: AssetClass,}
tx new_order() { input source { from: Sender, min_amount: fees + Bid(1) + Ada(2000000), }
mint { amount: ControlToken(1), redeemer: (), }
output change { to: Sender, amount: source - Ada(2000000)- fees - Bid(1), }
output order { to: OrderBook, amount: Ada(2000000) + Bid(1), datum: OrderDatum { info: OrderInfo { // Problem: serialize address into datum sender_address: 0x00eb5a3cf99aa1d77357864ed2d2fcbdb07a292363f0944122c510a30d58305b9bc8f9bea6e23d4e459d46aacc606eb20b29a27024175549e9, token: DatumValue { // Problem: serialize the ASK token asset_class: AssetClass { policy: 0x13a0e59ca61ab277e909ffd20def27d296051fbc634cf623c02322a5, name: "ASK", }, amount: 1, }, }, // Problem: serialize the CONTROL token control_asset_class: AssetClass { policy: 0x13a0e59ca61ab277e909ffd20def27d296051fbc634cf623c02322a5, name: "CONTROL", }, }, }}