|
@@ -9,6 +9,7 @@ import {
|
|
TransactionMessageWithBlockhashLifetime,
|
|
TransactionMessageWithBlockhashLifetime,
|
|
TransactionSigner,
|
|
TransactionSigner,
|
|
airdropFactory,
|
|
airdropFactory,
|
|
|
|
+ appendTransactionMessageInstructions,
|
|
createSolanaRpc,
|
|
createSolanaRpc,
|
|
createSolanaRpcSubscriptions,
|
|
createSolanaRpcSubscriptions,
|
|
createTransactionMessage,
|
|
createTransactionMessage,
|
|
@@ -21,6 +22,12 @@ import {
|
|
setTransactionMessageLifetimeUsingBlockhash,
|
|
setTransactionMessageLifetimeUsingBlockhash,
|
|
signTransactionMessageWithSigners,
|
|
signTransactionMessageWithSigners,
|
|
} from '@solana/web3.js';
|
|
} from '@solana/web3.js';
|
|
|
|
+import {
|
|
|
|
+ TOKEN_PROGRAM_ADDRESS,
|
|
|
|
+ getInitializeMintInstruction,
|
|
|
|
+ getMintSize,
|
|
|
|
+} from '../src/index.js';
|
|
|
|
+import { getCreateAccountInstruction } from '@solana-program/system';
|
|
|
|
|
|
type Client = {
|
|
type Client = {
|
|
rpc: Rpc<SolanaRpcApi>;
|
|
rpc: Rpc<SolanaRpcApi>;
|
|
@@ -78,3 +85,36 @@ export const signAndSendTransaction = async (
|
|
export const getBalance = async (client: Client, address: Address) =>
|
|
export const getBalance = async (client: Client, address: Address) =>
|
|
(await client.rpc.getBalance(address, { commitment: 'confirmed' }).send())
|
|
(await client.rpc.getBalance(address, { commitment: 'confirmed' }).send())
|
|
.value;
|
|
.value;
|
|
|
|
+
|
|
|
|
+export const createMint = async (
|
|
|
|
+ client: Client,
|
|
|
|
+ authority: TransactionSigner
|
|
|
|
+): Promise<Address> => {
|
|
|
|
+ const space = BigInt(getMintSize());
|
|
|
|
+ const [transactionMessage, rent, mint] = await Promise.all([
|
|
|
|
+ createDefaultTransaction(client, authority),
|
|
|
|
+ client.rpc.getMinimumBalanceForRentExemption(space).send(),
|
|
|
|
+ generateKeyPairSigner(),
|
|
|
|
+ ]);
|
|
|
|
+ const instructions = [
|
|
|
|
+ getCreateAccountInstruction({
|
|
|
|
+ payer: authority,
|
|
|
|
+ newAccount: mint,
|
|
|
|
+ lamports: rent,
|
|
|
|
+ space,
|
|
|
|
+ programAddress: TOKEN_PROGRAM_ADDRESS,
|
|
|
|
+ }),
|
|
|
|
+ getInitializeMintInstruction({
|
|
|
|
+ mint: mint.address,
|
|
|
|
+ decimals: 2,
|
|
|
|
+ mintAuthority: authority.address,
|
|
|
|
+ }),
|
|
|
|
+ ];
|
|
|
|
+ await pipe(
|
|
|
|
+ transactionMessage,
|
|
|
|
+ (tx) => appendTransactionMessageInstructions(instructions, tx),
|
|
|
|
+ (tx) => signAndSendTransaction(client, tx)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return mint.address;
|
|
|
|
+};
|