Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"lint:fix": "eslint --fix --ext js,ts,tsx src",
"format": "prettier --write .",
"format:check": "prettier --check .",
"example:create-mint": "tsx src/example.ts"
"example:single-signer": "tsx src/examples/single-signer.ts",
"example:multisig": "tsx src/examples/multisig.ts"
},
"publishConfig": {
"access": "public",
Expand All @@ -46,7 +47,8 @@
"dependencies": {
"@solana-program/system": "^0.7.0",
"@solana-program/token": "^0.5.1",
"@solana-program/token-2022": "^0.4.0"
"@solana-program/token-2022": "^0.4.0",
"@solana/rpc-types": "^2.1.0"
},
"devDependencies": {
"@eslint/js": "^9.22.0",
Expand Down
3 changes: 3 additions & 0 deletions clients/js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 31 additions & 27 deletions clients/js/src/create-mint.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import {
Address,
appendTransactionMessageInstructions,
CompilableTransactionMessage,
createTransactionMessage,
fetchEncodedAccount,
getSignatureFromTransaction,
GetAccountInfoApi,
GetMinimumBalanceForRentExemptionApi,
IInstruction,
KeyPairSigner,
pipe,
Rpc,
RpcSubscriptions,
sendAndConfirmTransactionFactory,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners,
SolanaRpcApi,
SolanaRpcSubscriptionsApi,
TransactionMessageWithBlockhashLifetime,
} from '@solana/kit';
import { getMintSize } from '@solana-program/token-2022';
import { getTransferSolInstruction } from '@solana-program/system';
Expand All @@ -24,22 +22,36 @@ import {
getBackpointerSize,
getCreateMintInstruction,
} from './generated';
import { Blockhash } from '@solana/rpc-types';

export const executeCreateMint = async ({
export interface CreateMintTxArgs {
rpc: Rpc<GetAccountInfoApi & GetMinimumBalanceForRentExemptionApi>;
blockhash: {
blockhash: Blockhash;
lastValidBlockHeight: bigint;
};
unwrappedMint: Address;
wrappedTokenProgram: Address;
payer: KeyPairSigner;
idempotent: boolean;
}

export interface CreateMintTxResult {
wrappedMint: Address;
backpointer: Address;
fundedWrappedMintLamports: bigint;
fundedBackpointerLamports: bigint;
tx: CompilableTransactionMessage & TransactionMessageWithBlockhashLifetime;
}

export async function createMintTx({
rpc,
rpcSubscriptions,
blockhash,
unwrappedMint,
wrappedTokenProgram,
payer,
idempotent = false,
}: {
rpc: Rpc<SolanaRpcApi>;
rpcSubscriptions: RpcSubscriptions<SolanaRpcSubscriptionsApi>;
unwrappedMint: Address;
wrappedTokenProgram: Address;
payer: KeyPairSigner;
idempotent: boolean;
}) => {
}: CreateMintTxArgs): Promise<CreateMintTxResult> {
const [wrappedMint] = await findWrappedMintPda({
unwrappedMint,
wrappedTokenProgram: wrappedTokenProgram,
Expand Down Expand Up @@ -101,26 +113,18 @@ export const executeCreateMint = async ({
}),
);

const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();

// Build transaction
const tx = pipe(
createTransactionMessage({ version: 0 }),
tx => setTransactionMessageFeePayerSigner(payer, tx),
tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
tx => setTransactionMessageLifetimeUsingBlockhash(blockhash, tx),
tx => appendTransactionMessageInstructions(instructions, tx),
);

// Send tx
const signedTransaction = await signTransactionMessageWithSigners(tx);
const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
await sendAndConfirm(signedTransaction, { commitment: 'confirmed' });

return {
wrappedMint,
backpointer,
signature: getSignatureFromTransaction(signedTransaction),
tx,
fundedWrappedMintLamports,
fundedBackpointerLamports,
};
};
}
86 changes: 0 additions & 86 deletions clients/js/src/example.ts

This file was deleted.

Loading