-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmint_nft_cip25.ts
58 lines (48 loc) · 1.75 KB
/
mint_nft_cip25.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Trang chủ Lucid tại --> https://lucid.spacebudz.io/
// Trang chủ Blockfrost --> https://blockfrost.io
// minting token tuan thu CIP25
import { Blockfrost, Lucid, fromText } from "https://deno.land/x/lucid/mod.ts";
const BLOCKFROST_API_KEY = Deno.env.get("BLOCKFROST_API_KEY");
const ALICE_MNEMONIC = Deno.env.get("ALICE_MNEMONIC");
const lucid = await Lucid.new(
new Blockfrost(
"https://cardano-preview.blockfrost.io/api/v0", BLOCKFROST_API_KEY,), "Preview",);
//Khai báo ví Alice
lucid.selectWalletFromSeed(ALICE_MNEMONIC);
//Tạo Minting Policy
const { paymentCredential } = lucid.utils.getAddressDetails(await lucid.wallet.address(),);
const mintingPolicy = lucid.utils.nativeScriptFromJson(
{
type: "all",
scripts: [
{ type: "sig", keyHash: paymentCredential.hash },
{
type: "before",
slot: lucid.utils.unixTimeToSlot(Date.now() + 1000000),
},
],
},
);
const asset_name = "VIETNAM"
const policyId = lucid.utils.mintingPolicyToId(mintingPolicy);
const unit = policyId + fromText(asset_name);
const filename = "ipfs://QmZcQwd5TEymQz9pmBsEZhTVdqscaEbfsnHNDEVf74MVkq";
const metadata = {
[policyId]: {
[asset_name]: {
"description": "VIETNAM: The hidden charm",
"id": "1",
"image": filename,
"name": asset_name
}
}
};
const tx = await lucid.newTx()
.mintAssets({ [unit]: BigInt(1) }) //tên và số lượng
.attachMetadata(721, metadata) //attachMetadata
.validTo(Date.now() + 200000)
.attachMintingPolicy(mintingPolicy)
.complete();
const signedTx = await tx.sign().complete();
const txHash = await signedTx.submit();
console.log(`ID giao dịch là ${txHash}`)