-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsetAuthority.js
82 lines (71 loc) · 2.42 KB
/
setAuthority.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
72
73
74
75
76
77
78
79
80
81
82
import {
clusterApiUrl,
Connection,
PublicKey,
Keypair,
Transaction,
sendAndConfirmTransaction,
} from "@solana/web3.js";
import {
AuthorityType,
createSetAuthorityInstruction,
setAuthority,
} from "@solana/spl-token";
import bs58 from "bs58";
(async() => {
// connection
const connection = new Connection("https://wiser-summer-lake.solana-mainnet.quiknode.pro/33ce97085fd8e112069832f5fd92acac91f2e3c0", "confirmed");
// 5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8
const feePayer = Keypair.fromSecretKey(
bs58.decode(
"2TCaVsZLvsj3MnhkV2QvM17KShnJZwgfz1P6NX66WfHZmBZ7kUrbtDTDAMXKCoGSMmzhK1GEznwKvBq3uorZG1Up",
),
);
// G2FAbFQPFa5qKXCetoFZQEvF9BVvCKbvUZvodpVidnoY
const alice = Keypair.fromSecretKey(
bs58.decode(
"3rQVoYGttUhqe2xRZpAXX72qcBaHLDi23agZ8ax85o3ueyC1jqN93DZStDNyVaa2uddhBkPM4vzAzdfdp5gQkxKr",
),
);
const randomGuy = new PublicKey("5eFEFVkw73HEH6JFYv9JRXhbZgUsQNYMowGVsqyjA7Ff");
const mintPubkey = new PublicKey(
"CQY7aJx5BwfP3GmVNCek5WPtUnjbsfZw7m4PL8XwpS7j",
);
// authority type
// 1) for mint account
// AuthorityType.MintTokens
// AuthorityType.FreezeAccount
// 2) for token account
// AuthorityType.AccountOwner
// AuthorityType.CloseAccount
// 1) use build-in function
{
let txhash = await setAuthority(
connection, // connection
feePayer, // payer
mintPubkey, // mint account || token account
alice, // current authority
AuthorityType.MintTokens, // authority type
randomGuy, // new authority (you can pass `null` to close it)
);
console.log(`txhash: ${txhash}`);
}
// or
// 2) compose by yourself
{
let tx = new Transaction().add(
createSetAuthorityInstruction(
mintPubkey, // mint account || token account
alice.publicKey, // current auth
AuthorityType.MintTokens, // authority type
feePayer.publicKey, // new auth (you can pass `null` to close it)
),
);
console.log(
`txhash: ${await sendAndConfirmTransaction(connection, tx, [
feePayer,
alice /* fee payer + origin auth */,
])}`,
);
}
})();