diff --git a/.phrase.prv b/.phrase.prv new file mode 100644 index 0000000..5822180 --- /dev/null +++ b/.phrase.prv @@ -0,0 +1 @@ +receive company catalog screen erase shallow verb wool asthma bring north average side chunk bulk submit hip spend antique unaware purity right fat someone \ No newline at end of file diff --git a/cardano-address b/cardano-address deleted file mode 100644 index 6ac0a93..0000000 Binary files a/cardano-address and /dev/null differ diff --git a/deno_setup.sh b/deno_setup.sh index 4d414ac..448891d 100644 --- a/deno_setup.sh +++ b/deno_setup.sh @@ -1,7 +1,4 @@ #! /bin/bash -set -euo pipefail - -apt-get update -apt-get install unzip -y -curl -fsSL https://deno.land/install.sh | sh +root@codespaces-a48a05:/workspaces/cardano-developer-starter-kit# demo run --allow-all ./lucid1.ts +bash: demo: command not found diff --git a/hello-world/.github/workflows/continuous-integration.yml b/hello-world/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..ba419b4 --- /dev/null +++ b/hello-world/.github/workflows/continuous-integration.yml @@ -0,0 +1,18 @@ +name: Continuous Integration + +on: + push: + branches: ["main"] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: aiken-lang/setup-aiken@v1 + with: + version: v1.1.16 + - run: aiken fmt --check + - run: aiken check -D + - run: aiken build diff --git a/hello-world/.gitignore b/hello-world/.gitignore new file mode 100644 index 0000000..ff7811b --- /dev/null +++ b/hello-world/.gitignore @@ -0,0 +1,6 @@ +# Aiken compilation artifacts +artifacts/ +# Aiken's project working directory +build/ +# Aiken's default documentation export +docs/ diff --git a/hello-world/README.md b/hello-world/README.md new file mode 100644 index 0000000..194bbfe --- /dev/null +++ b/hello-world/README.md @@ -0,0 +1,65 @@ +# hello-world + +Write validators in the `validators` folder, and supporting functions in the `lib` folder using `.ak` as a file extension. + +```aiken +validator my_first_validator { + spend(_datum: Option, _redeemer: Data, _output_reference: Data, _context: Data) { + True + } +} +``` + +## Building + +```sh +aiken build +``` + +## Configuring + +**aiken.toml** +```toml +[config.default] +network_id = 41 +``` + +Or, alternatively, write conditional environment modules under `env`. + +## Testing + +You can write tests in any module using the `test` keyword. For example: + +```aiken +use config + +test foo() { + config.network_id + 1 == 42 +} +``` + +To run all tests, simply do: + +```sh +aiken check +``` + +To run only tests matching the string `foo`, do: + +```sh +aiken check -m foo +``` + +## Documentation + +If you're writing a library, you might want to generate an HTML documentation for it. + +Use: + +```sh +aiken docs +``` + +## Resources + +Find more on the [Aiken's user manual](https://aiken-lang.org). diff --git a/hello-world/aiken.lock b/hello-world/aiken.lock new file mode 100644 index 0000000..3195130 --- /dev/null +++ b/hello-world/aiken.lock @@ -0,0 +1,15 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +[[requirements]] +name = "aiken-lang/stdlib" +version = "v2.2.0" +source = "github" + +[[packages]] +name = "aiken-lang/stdlib" +version = "v2.2.0" +requirements = [] +source = "github" + +[etags] diff --git a/hello-world/aiken.toml b/hello-world/aiken.toml new file mode 100644 index 0000000..94a4200 --- /dev/null +++ b/hello-world/aiken.toml @@ -0,0 +1,18 @@ +name = "aiken-lang/hello-world" +version = "0.0.0" +compiler = "v1.1.16" +plutus = "v3" +license = "Apache-2.0" +description = "Aiken contracts for project 'aiken-lang/hello-world'" + +[repository] +user = "aiken-lang" +project = "hello-world" +platform = "github" + +[[dependencies]] +name = "aiken-lang/stdlib" +version = "v2.2.0" +source = "github" + +[config] diff --git a/hello-world/plutus.json b/hello-world/plutus.json new file mode 100644 index 0000000..8f8d4f8 --- /dev/null +++ b/hello-world/plutus.json @@ -0,0 +1,101 @@ +{ + "preamble": { + "title": "aiken-lang/hello-world", + "description": "Aiken contracts for project 'aiken-lang/hello-world'", + "version": "0.0.0", + "plutusVersion": "v3", + "compiler": { + "name": "Aiken", + "version": "v1.1.16+23061c0" + }, + "license": "Apache-2.0" + }, + "validators": [ + { + "title": "placeholder.placeholder.mint", + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + }, + { + "title": "placeholder.placeholder.spend", + "datum": { + "title": "_datum", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + }, + { + "title": "placeholder.placeholder.withdraw", + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + }, + { + "title": "placeholder.placeholder.publish", + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + }, + { + "title": "placeholder.placeholder.vote", + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + }, + { + "title": "placeholder.placeholder.propose", + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + }, + { + "title": "placeholder.placeholder.else", + "redeemer": { + "schema": {} + }, + "compiledCode": "58d001010029800aba2aba1aab9eaab9dab9a48888966002646465300130053754003300700398038012444b30013370e9000001c4c98dd7180518049baa0048acc004cdc3a400400713233226300b001300b300c0013009375400915980099b874801000e264c601460126ea80122b30013370e9003001c4c8cc898dd698058009805980600098049baa0048acc004cdc3a40100071326300a3009375400913233226375a60160026016601800260126ea8011007200e401c80390070c018c01c004c018004c00cdd5003452689b2b20021", + "hash": "f2388d136606a27c4a531d0040c3e12e07eb95cd5011793c160707dc" + } + ], + "definitions": { + "Data": { + "title": "Data", + "description": "Any Plutus data." + } + } +} \ No newline at end of file diff --git a/hello-world/validators/placeholder.ak b/hello-world/validators/placeholder.ak new file mode 100644 index 0000000..c2123c1 --- /dev/null +++ b/hello-world/validators/placeholder.ak @@ -0,0 +1,40 @@ +use cardano/address.{Credential} +use cardano/assets.{PolicyId} +use cardano/certificate.{Certificate} +use cardano/governance.{ProposalProcedure, Voter} +use cardano/transaction.{Transaction, OutputReference} + +use aiken/primitive/string +use cardano/transaction.{OutputReference, Transaction} + +pub type Redeemer { +msg: ByteArray, +} + +validator alwayssuccess { +spend( +_datum: Option, +redeemer: Redeemer, +_utxo: OutputReference, +_self: Transaction, +) { +// ctx: ScriptContext, +trace @"redeemer": string.from_bytearray(redeemer.msg) +let a = True +a? +} + +else(_) { +fail +} +} + // // If needs be, remove any of unneeded handlers above, and use: + // + // else(_ctx: ScriptContext) { + // todo @"fallback logic if none of the other purposes match" + // } + // + // // You will also need an additional import: + // // + // // use cardano/script_context.{ScriptContext} + diff --git a/labs/lab01/keygen.sh b/labs/lab01/keygen.sh index 9ef0602..d26d84e 100644 --- a/labs/lab01/keygen.sh +++ b/labs/lab01/keygen.sh @@ -25,7 +25,7 @@ cardano-cli key verification-key --signing-key-file stake.skey \ # cardano-address key hash < stake.xvk > stake.vkh # cardano-address address delegation $(cat stake.vkh) < payment.addr > base.addr -cardano-cli address build --testnet-magic 2 \ +cardano-cli conway address build --testnet-magic 2 \ --payment-verification-key-file payment.xvk \ --stake-verification-key-file stake.xvk \ --out-file base.addr diff --git a/labs/lab02/simple_tx.sh b/labs/lab02/simple_tx.sh index b43e8d1..305293a 100644 --- a/labs/lab02/simple_tx.sh +++ b/labs/lab02/simple_tx.sh @@ -6,9 +6,9 @@ cardano-cli query utxo $testnet --address $address #chỉnh sửa lại giá trị các biến BOB_ADDR="addr_test1qz8shh6wqssr83hurdmqx44js8v7tglg9lm3xh89auw007dd38kf3ymx9c2w225uc7yjmplr794wvc96n5lsy0wsm8fq9n5epq" -VALUE=1000000 +VALUE=2000000 -UTXO_IN=cccfd8642e237ea1d7465a42d3851d1a7902ba9abb9fab46b1b12b69df02ef4b#2 +UTXO_IN=21dd41ec497ed5aee3712199d6abb2be8c438108768f69f355bdf72698eadc3e#5 # B1. Xây dựng giao dịch (Build Tx) diff --git a/lucid/lucid1.ts b/lucid/lucid1.ts new file mode 100644 index 0000000..d032cd5 --- /dev/null +++ b/lucid/lucid1.ts @@ -0,0 +1,126 @@ +import { Blockfrost, Lucid, Crypto ,fromText,Data, Addresses, } from "https://deno.land/x/lucid/mod.ts"; + +const lucid = new Lucid({ + provider: new Blockfrost( + "https://cardano-preview.blockfrost.io/api/v0", + "previewjeV1C6kZZcdvOk8U2RS7DnGt5XwwvaWS" + ), +}); + + +const seed="receive company catalog screen erase shallow verb wool asthma bring north average side chunk bulk submit hip spend antique unaware purity right fat someone" +lucid.selectWalletFromSeed(seed,{addressType:"Base", index:0}) + +//const address = await lucid.wallet.address(); +//console.log(`địa chỉ gửi: ${address}`) + +//const utxos = await lucid.wallet.getUtxos(); +//const utxo=utxos[1]; +//console.log (utxo) +//console.log (utxos) + +//console.log(lucid); + +// Lấy thông tin assets từ UTxO +//const assets = utxo.assets; + +// Hiển thị thông tin assets +// console.log("Assets:", assets); + +// Hiển thị toàn bộ tài sản và giá trị của chúng +//for (const assetname in assets) { +// console.log(`Assetname: ${assetname}, Value: ${assets[assetname]}`); +//} +//const [scriptUtxo] = await lucid.utxosAt("addr_test1qzldl9u0j6ap7mdugtdcre43f8dfrnv7uqd3a6furpyuzw3z70zawv8g3tyg7uh833x50geeul2vpyujyzac0d6dmgcsyu5akw"); +//console.log(scriptUtxo) +//const receiverAddress = "addr_test1qzldl9u0j6ap7mdugtdcre43f8dfrnv7uqd3a6furpyuzw3z70zawv8g3tyg7uh833x50geeul2vpyujyzac0d6dmgcsyu5akw"; + +//try { + + //const tx = await lucid.newTx() + //.payTo(receiverAddress, { lovelace: 1_000_000n }) + // .commit(); + + // 5. Ký và gửi + // const signedTx = await tx.sign().commit(); + // const txHash = await signedTx.submit(); + + //console.log("Giao dịch thành công!"); + //console.log("Tx Hash:", txHash); + +//} catch (error) { + // console.error(" Lỗi:", error); +//} +//async function createSendNativeTokens( + // receiverAddress: string, + // policyId: string, + // assetName: string, + //amount: bigint +//) { + //try { + // const assetId = policyId + fromText(assetName); + + // 👇 Sử dụng .commit() thay vì .complete() + //const tx = await lucid.newTx() + // .payTo(receiverAddress, { + // [assetId]: amount, + // lovelace: 2_000_000n // Thêm 2 ADA + //}) + //.commit(); + + //return tx; + //} catch (error) { + // console.error("Lỗi khi tạo giao dịch:", error); + //throw error; + //} +//} + +// 3. Sử dụng hàm +//const tx = await createSendNativeTokens( + //"addr_test1qzldl9u0j6ap7mdugtdcre43f8dfrnv7uqd3a6furpyuzw3z70zawv8g3tyg7uh833x50geeul2vpyujyzac0d6dmgcsyu5akw", + //"2a5d661ac065dec81c73215d7e667d19ac34ea884f9917a3bc8357fb", + //"BK03_TOKENS", + //1n +//); + +// 👇 Ký và gửi (cũng dùng .commit()) +//const signedTx = await tx.sign().commit(); +//const txHash = await signedTx.submit(); +//console.log(" Giao dịch thành công! Tx Hash:", txHash); +//Deno.exit(0); // Thoát chương trình +const toAddress = "addr_test1qzldl9u0j6ap7mdugtdcre43f8dfrnv7uqd3a6furpyuzw3z70zawv8g3tyg7uh833x50geeul2vpyujyzac0d6dmgcsyu5akw"; + +async function createSendAdawithDatum(toAddress: string, datum: any, amount: bigint) { + const tx = await lucid.newTx() + .payToWithData(toAddress, datum, { lovelace: amount }) + .commit(); + return tx; +} +const VestingSchema = Data.Object({ + lock_until: Data.Integer(), + beneficiary: Data.Bytes(), +}); + +const deadlineDate: Date = new Date("2026-06-09T00:00:00Z"); +const deadlinePosIx = BigInt(deadlineDate.getTime()); +const { payment } = Addresses.inspect( + "addr_test1qzldl9u0j6ap7mdugtdcre43f8dfrnv7uqd3a6furpyuzw3z70zawv8g3tyg7uh833x50geeul2vpyujyzac0d6dmgcsyu5akw" +); + +const d = { + lock_until: deadlinePosIx, + beneficiary: payment?.hash +}; + +const datum = await Data.to(d, VestingSchema); + +console.log(datum); +//Deno.exit(0); // Thoát chương trình + +const tx = await createSendAdawithDatum(toAddress, datum, 100000n); +//console.log(tx); +//Deno.exit(0); // Thoát chương trình + +let signedTx = await tx.sign().commit(); +let txHash = await signedTx.submit(); +console.log('Mã giao dịch là: ' + txHash); \ No newline at end of file diff --git a/lucid/lucid2.ts b/lucid/lucid2.ts new file mode 100644 index 0000000..e8ac12e --- /dev/null +++ b/lucid/lucid2.ts @@ -0,0 +1,71 @@ +import { Blockfrost, Lucid, Crypto ,fromText,Data, Addresses, } from "https://deno.land/x/lucid/mod.ts"; + +const lucid = new Lucid({ + provider: new Blockfrost( + "https://cardano-preview.blockfrost.io/api/v0", + "previewjeV1C6kZZcdvOk8U2RS7DnGt5XwwvaWS" + ), +}); + + +const seed="receive company catalog screen erase shallow verb wool asthma bring north average side chunk bulk submit hip spend antique unaware purity right fat someone" +lucid.selectWalletFromSeed(seed,{addressType:"Base", index:0}) + +const address = await lucid.wallet.address(); // Bech32 address +console.log(`D/c ví gửi: ${address}`); + +async function createMintingScripts(slot_in: bigint) { + const { payment } = Addresses.inspect( + await lucid.wallet.address(), + ); + + const mintingScripts = lucid.newScript({ + type: "All", + scripts: [ + { type: "Sig", keyHash: payment.hash }, + { + type: "Before", + slot: slot_in + }, + ], + }, + ); + + return mintingScripts; + } + async function mintToken(policyId: string, tokenName: string, amount: bigint, slot_in: bigint) { + const unit = policyId + fromText(tokenName); + + // ================= Tạo metadata ==== + const metadata = { + [policyId]: { + [tokenName]: { + "description": "This is Token minted by LUCID", + "name": `${tokenName}`, + "id":1 , + "image": "ipfs://QmRoaRZ7QGX9EiLkZoGJfC5is9VUN19P8nsra2aWqoDUm1" + } + } + }; + + console.log(metadata); + + const tx = await lucid.newTx() + .mint({ [unit]: amount }) + .validTo(Date.now() + 200000) + .attachScript(await createMintingScripts(slot_in)) + .attachMetadata(721, metadata) + .commit(); + +return tx; + + } + + const slot_in = BigInt(lucid.utils.unixTimeToSlots(Date.now())); //BigInt(84885593). + console.log(`Slot: ${slot_in}`); + Deno.exit(0); //.Thoat . chương. trinh + + + + + \ No newline at end of file diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..591cc7d --- /dev/null +++ b/metadata.json @@ -0,0 +1,5 @@ +{ + "674": { + "msg": ["Nguyen Quoc Thai + 142"] + } + } \ No newline at end of file diff --git a/metadata.metadatajson b/metadata.metadatajson new file mode 100644 index 0000000..36965e0 --- /dev/null +++ b/metadata.metadatajson @@ -0,0 +1,5 @@ +{ + "674": { + "msg": ["metadata message"] + } +} \ No newline at end of file diff --git a/mithril.sh b/mithril.sh old mode 100644 new mode 100755 diff --git a/nft_project/policy/policyID b/nft_project/policy/policyID new file mode 100644 index 0000000..8aa0297 --- /dev/null +++ b/nft_project/policy/policyID @@ -0,0 +1 @@ +76abea9db33d15b4c19038a91e93e383cf1642ff12e1d1b6d9425706 diff --git a/payment.xsk b/payment.xsk new file mode 100644 index 0000000..eb9f46c --- /dev/null +++ b/payment.xsk @@ -0,0 +1 @@ +addr_xsk1nzqu4gskmm48yg679servgfy3vfuj9l4vps0hrh5u6dr6dkw2fqr52zznmzer72n8q6p0p46qqev7a3q0msw8za8pfu48sn9jvagyuapsw7jva9nq4cd7up5x47hmp54lwps6n3flshczhxpjnu622xr9qfmsss7 \ No newline at end of file diff --git a/payment.xvk b/payment.xvk new file mode 100644 index 0000000..8bc81d4 --- /dev/null +++ b/payment.xvk @@ -0,0 +1 @@ +addr_vk1ywzz977zf2zav67qn20yualtg50nz4haplxc53hsntuxth8swpuqev8qs8 \ No newline at end of file diff --git a/root.xsk b/root.xsk new file mode 100644 index 0000000..8934407 --- /dev/null +++ b/root.xsk @@ -0,0 +1 @@ +root_xsk16pz8w3cfujlc2zn5yajdn3fr32kwymea9wsmu9h3k4gsgfww2fqxgqy7plr3mrjeg76gl0rhmm7549s5fl2gfrk4sq050mjw8zq07jajdq3pggr0fuwrxelc8m4nyu5zr9sef5wxnnvcshnhvtf0s9qg95ag9a8v \ No newline at end of file diff --git a/stake.xsk b/stake.xsk new file mode 100644 index 0000000..9eb2daa --- /dev/null +++ b/stake.xsk @@ -0,0 +1 @@ +stake_xsk17pfqhppn5pl2r22dsry9sp72744zp3xdulkzfcvgjfpn7wxw2fqyk2j3jmzuljw7njq4cds8204szdflz9qnpj9zlhv7ryrmuzux6jmv9k328rkfkjsh7zpfly9phuqq77x62tl9cegh2mlt6zu6rxanwqhealvr \ No newline at end of file diff --git a/stake.xvk b/stake.xvk new file mode 100644 index 0000000..12f5641 --- /dev/null +++ b/stake.xvk @@ -0,0 +1 @@ +stake_vk1amvzh35pyvjddtzz3r09ysucu0v4u3d6ryxeueu4hw8q60edre4sdrkxuw \ No newline at end of file diff --git a/tokens/metadata.json b/tokens/metadata.json new file mode 100644 index 0000000..6da5976 --- /dev/null +++ b/tokens/metadata.json @@ -0,0 +1,13 @@ +{ + "721": { + "899568f8c6388662cb4bdcbefc4461becac93b4c202cae1a707f137f": { + "Nguyen Quoc Thai_142": { + "Class": "C2VN_BK03", + "name": "Nguyen Quoc Thai", + "Student_no": "142", + "Module": "module 1- CLI", + "image": "ipfs://QmPApB53fNKfJnhD8afrW2Sr7h451Lz2f1CKgJjg6r8EER" + } + } + } +} diff --git a/tokens/policy/policyID b/tokens/policy/policyID new file mode 100644 index 0000000..77a130f --- /dev/null +++ b/tokens/policy/policyID @@ -0,0 +1 @@ +899568f8c6388662cb4bdcbefc4461becac93b4c202cae1a707f137f