-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateAsset.js
70 lines (49 loc) · 1.94 KB
/
CreateAsset.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
57
58
59
60
61
62
63
64
65
66
67
68
69
const algosdk = require('algosdk');
const fs = require('fs');
async function deployToken() {
// Read the account details from JSON
const accountData = JSON.parse(fs.readFileSync('account.json', 'utf8'));
const { address, privateKey } = accountData;
// Convert the private key from base64 string back to Uint8Array
const privateKeyUint8 = new Uint8Array(Buffer.from(privateKey, 'base64'));
// Connect to the Algorand node
console.log("Connecting to Algorand Testnet");
const algodToken={
"x-api-key": "dazHBmiKz96MAwUxVMdxV9JAQKjDWokYMihpFfLd" // fill in yours
};
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const algodPort = "";
const algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);
// Get suggested transaction parameters
const suggestedParams = await algodClient.getTransactionParams().do();
// Create an asset creation transaction
console.log("Creating the Token Metadata");
const txn = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({
from: address,
suggestedParams,
defaultFrozen: false,
unitName: 'Kim', // Symbol
assetName: 'Kim Jong-Un Coin', // Name of the asset
manager: address,
reserve: address,
freeze: address,
clawback: address,
total: 1000,
decimals: 0, // Decimals
});
// Sign the transaction
const signedTxn = algosdk.signTransaction(txn, privateKeyUint8);
// Submit the transaction to the network
await algodClient.sendRawTransaction(signedTxn.blob).do();
// Wait for confirmation
const result = await algosdk.waitForConfirmation(algodClient, txn.txID().toString(), 3);
console.log("Token deployed");
const assetIndex = result['asset-index'];
console.log(`Asset ID created: ${assetIndex}`);
// Display AlgoExplorer URL
const url = `https://testnet.algoexplorer.io/asset/${assetIndex}`;
console.log(`Asset URL: ${url}`);
// End the console
process.exit();
}
deployToken();