forked from lalalune/duck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duck-functions.js
56 lines (54 loc) · 1.99 KB
/
duck-functions.js
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
import interfaceFactory from '@psychedelic/dab-js/dist/idls/dip_721_v2.did.js';
export const plugLogin = async () => {
const canisterId = "q47yz-iyaaa-aaaam-qambq-cai";
// const canisterId = "6hgw2-nyaaa-aaaai-abkqq-cai";
const whitelist = [canisterId];
const standard = "DIP721v2";
console.log('logging in...');
await window.ic.plug.requestConnect({whitelist});
console.log("Plug has logged in, grabbing actor...");
const principal = await window.ic.plug.agent.getPrincipal();
console.log("Your principal is " + principal);;
const connected = await window.ic.plug.isConnected();
if (connected) {
console.log("You have been logged in with plug.");
} else {
console.log("Please try again.");
}
const actor = await window.ic.plug.createActor({canisterId, interfaceFactory});
console.log("Actor created successfully, getting token supply...");
const indexResult = await actor.totalSupply();
const stringLength = indexResult.toString().length;
const tokenIndexRaw = Number(await indexResult.toString().slice(0,stringLength));
const tokenIndex = tokenIndexRaw + 1;
console.log("Next token in line is " + tokenIndex);
console.log("Minting nft...");
const properties = [
[
"location",
{
"TextContent": "https://qgh4x-kyaaa-aaaaj-afk5q-cai.raw.ic0.app/playground/preview.jpg"
}
],
[
"glb",
{
"TextContent": "https://qgh4x-kyaaa-aaaaj-afk5q-cai.raw.ic0.app/playground/Duck.glb"
}
],
[
"json",
{
"TextContent": "{\"Achievement Unlocked\":\"Minted!\"}"
}
]
];
const mintResult = await actor.mint(principal, tokenIndex, properties);
const formattedResults = Object.keys(mintResult);
console.log(formattedResults);
if (formattedResults.includes("Ok")) {
alert("NFT Minted Successfully");
} else {
alert("NFT Minting Failed: \nSee your console log (F12) for details.");
}
}