|
| 1 | +defmodule AlwaysSucceedMint do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + alias Sutra.Cardano.Address |
| 5 | + alias Sutra.Cardano.Asset |
| 6 | + alias Sutra.Cardano.Script |
| 7 | + alias Sutra.Crypto.Key |
| 8 | + alias Sutra.Data |
| 9 | + |
| 10 | + @compiled_code "589a010100323232323223225333004323232323232533300a3370e9000000899251375c601a60186ea800854ccc028cdc3a4004002264664464a66601c66e1d2000300f37540042a66601c66e1cdd6980898081baa00200114a22c2c6eb4018c038004c038c03c004c030dd50010b18051baa001300b300c003300a002300900230090013006375400229309b2b1bae0015734aae7555cf2ba15745" |
| 11 | + |
| 12 | + def run() do |
| 13 | + |
| 14 | + mnemonic = |
| 15 | + "test test test test test test test test test test test test test test test test test test test test test test test sauce" |
| 16 | + |
| 17 | + {:ok, root_key} = Key.root_key_from_mnemonic(mnemonic) |
| 18 | + |
| 19 | + # deriving two account to have utxo to cover collateral |
| 20 | + {:ok, extended_key_acct1} = Key.derive_child(root_key, 0, 0) |
| 21 | + {:ok, wallet_address_1} = Key.address(extended_key_acct1, :preprod) |
| 22 | + |
| 23 | + |
| 24 | + {:ok, extended_key_acct2} = Key.derive_child(root_key, 1, 0) |
| 25 | + {:ok, wallet_address_2} = Key.address(extended_key_acct2, :preprod) |
| 26 | + |
| 27 | + simple_mint_script = |
| 28 | + @compiled_code |
| 29 | + |> Script.apply_params([Base.encode16("some-params", case: :lower)]) |
| 30 | + |> Script.new(:plutus_v3) |
| 31 | + |
| 32 | + mint_script_address = Address.from_script(simple_mint_script, :preprod) |
| 33 | + |
| 34 | + out_token_name = Base.encode16("YACI-DEVKIT-TEST", case: :lower) |
| 35 | + policy_id = Script.hash_script(simple_mint_script) |
| 36 | + |
| 37 | + out_value = |
| 38 | + Asset.zero() |
| 39 | + |> Asset.add(policy_id, out_token_name, 100) |
| 40 | + |
| 41 | + tx_id = |
| 42 | + Sutra.new_tx() |
| 43 | + |> Sutra.mint_asset(policy_id, %{out_token_name => 100}, simple_mint_script, Data.void()) |
| 44 | + |> Sutra.add_output(mint_script_address, out_value, {:inline_datum, 58}) |
| 45 | + |> Sutra.build_tx!(wallet_address: [wallet_address_1, wallet_address_2]) |
| 46 | + |> Sutra.sign_tx([extended_key_acct1, extended_key_acct2]) |
| 47 | + |> Sutra.submit_tx() |
| 48 | + |
| 49 | + IO.puts(" Tx submitted with : #{tx_id}") |
| 50 | + end |
| 51 | +end |
| 52 | + |
| 53 | +# Setup sutra package & init yaci provider |
| 54 | +Code.eval_file("setup.exs") |
| 55 | + |
| 56 | +AlwaysSucceedMint.run() |
0 commit comments