-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.ts
80 lines (68 loc) · 2.57 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// as used in https://www.youtube.com/watch?v=DQbt0-riooo
import * as mpl from "@metaplex-foundation/mpl-token-metadata";
import * as web3 from "@solana/web3.js";
import * as anchor from '@project-serum/anchor';
export function loadWalletKey(keypairFile:string): web3.Keypair {
const fs = require("fs");
const loaded = web3.Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())),
);
return loaded;
}
const INITIALIZE = false;
async function main(){
console.log("let's name some tokens!");
const myKeypair = loadWalletKey("/home/stant/stans-main-wallet/my-keypair.json");
const mint = new web3.PublicKey("HckzT6eDViZKqXZbuAGPwVwg9uWtc29bRWTzoLtQNTDN");
const seed1 = Buffer.from(anchor.utils.bytes.utf8.encode("metadata"));
const seed2 = Buffer.from(mpl.PROGRAM_ID.toBytes());
const seed3 = Buffer.from(mint.toBytes());
const [metadataPDA, _bump] = web3.PublicKey.findProgramAddressSync([seed1, seed2, seed3], mpl.PROGRAM_ID);
let creatorslist: { address: web3.PublicKey; share: number; verified: boolean }[] = [
{"address": myKeypair.publicKey, "share" : 100, "verified": true} ,
]
const accounts = {
metadata: metadataPDA,
mint,
mintAuthority: myKeypair.publicKey,
payer: myKeypair.publicKey,
updateAuthority: myKeypair.publicKey,
}
const dataV2 = {
name: "Algo Coin",
symbol: "ALZA",
uri: "https://raw.githubusercontent.com/StantonR-ZA/ZarCoin/main/algocoin/token_metadata.json",
// we don't need that
sellerFeeBasisPoints: 500,
creators: null,
collection: null,
uses: null
}
let ix;
if (INITIALIZE) {
const args = {
createMetadataAccountArgsV2: {
data: dataV2,
isMutable: true,
updateAuthority: myKeypair.publicKey,
}
};
ix = mpl.createCreateMetadataAccountV2Instruction(accounts, args);
} else {
const args = {
updateMetadataAccountArgsV2: {
data: dataV2,
isMutable: true,
updateAuthority: myKeypair.publicKey,
primarySaleHappened: true
}
};
ix = mpl.createUpdateMetadataAccountV2Instruction(accounts, args)
}
const tx = new web3.Transaction();
tx.add(ix);
const connection = new web3.Connection("https://api.mainnet-beta.solana.com");
const txid = await web3.sendAndConfirmTransaction(connection, tx, [myKeypair]);
console.log(txid);
}
main();