-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_spl_token.js
71 lines (60 loc) · 1.46 KB
/
create_spl_token.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
70
71
const { web3, utils } = require("@project-serum/anchor")
const { readFile } = require("fs/promises")
const {
createMint,
mintTo,
createAssociatedTokenAccount,
} = require("@solana/spl-token")
/**
* Creates a new mint and mintTo a keypair
*
* Usage:
*
* node create_spl_token.js
*/
;(async () => {
const os = require("os")
/**
* Keypair location
*/
const pkString = (
await readFile(os.homedir() + "/.config/solana/viv.json")
).toString()
const pkArray = pkString
.replace("[", "")
.replace("]", "")
.split(",")
.map(Number)
const keyPair = web3.Keypair.fromSecretKey(new Uint8Array(pkArray))
const connection = new web3.Connection(
"https://psytrbhymqlkfrhudd.dev.genesysgo.net:8899/",
"confirmed"
)
console.log("Creating mint...")
const mint = await createMint(
connection,
keyPair,
keyPair.publicKey,
keyPair.publicKey,
9
)
const ataAddress = await utils.token.associatedAddress({
mint,
owner: keyPair.publicKey,
})
console.log("Fetching acc...")
const ataAccountInfo = await connection.getAccountInfo(ataAddress)
if (!ataAccountInfo) {
console.log("Creating ATA...")
await createAssociatedTokenAccount(
connection,
keyPair,
mint,
keyPair.publicKey
)
}
console.log("Minting..")
const qty = 100 ** 9
await mintTo(connection, keyPair, mint, ataAddress, keyPair, qty)
console.log(`Minted ${qty} ${mint} to ${keyPair.publicKey}!`)
})()