SDK
JavaScript SDK
Last updated October 12, 2026
Genesis JavaScript SDKのAPIリファレンスです。完全なチュートリアルについては、Launch PoolまたはPresaleを参照してください。
インストール
npm install @metaplex-foundation/genesis @metaplex-foundation/umi \
@metaplex-foundation/umi-bundle-defaults @metaplex-foundation/mpl-toolbox \
@metaplex-foundation/mpl-token-metadata
セットアップ
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { genesis } from '@metaplex-foundation/genesis';
import { mplTokenMetadata } from '@metaplex-foundation/mpl-token-metadata';
const umi = createUmi('https://api.mainnet-beta.solana.com')
.use(genesis())
.use(mplTokenMetadata());
完全な実装例については、Launch PoolまたはPresaleを参照してください。
インストラクションリファレンス
コア
| 関数 | 説明 |
|---|---|
| initializeV2() | Genesis Accountの作成とトークンの発行 |
| finalizeV2() | 設定のロックとローンチの有効化 |
バケット
| 関数 | 説明 |
|---|---|
| addLaunchPoolBucketV2() | 比例配分バケットの追加 |
| addPresaleBucketV2() | 固定価格販売バケットの追加 |
| addUnlockedBucketV2() | トレジャリー/受取人バケットの追加 |
Launch Pool操作
| 関数 | 説明 |
|---|---|
| depositLaunchPoolV2() | Launch PoolにSOLを入金 |
| withdrawLaunchPoolV2() | SOLの出金(入金期間中) |
| claimLaunchPoolV2() | トークンの請求(入金期間終了後) |
| refundLaunchPoolV2() | 入金の返金(しきい値未達またはソフトキャップ超過時) |
Presale操作
| 関数 | 説明 |
|---|---|
| depositPresaleV2() | PresaleにSOLを入金 |
| claimPresaleV2() | トークンの請求(入金期間終了後) |
管理者
| 関数 | 説明 |
|---|---|
| triggerBehaviorsV2() | 終了動作の実行 |
| revokeV2() | ミントおよびフリーズ権限の永久取り消し |
関数シグネチャ
initializeV2
await initializeV2(umi, {
baseMint, // Signer - new token keypair
quoteMint, // PublicKey - deposit token (wSOL)
fundingMode, // number - use 0
totalSupplyBaseToken, // bigint - supply with decimals
name, // string - token name
symbol, // string - token symbol
uri, // string - metadata URI
}).sendAndConfirm(umi);
finalizeV2
await finalizeV2(umi, {
baseMint, // PublicKey
genesisAccount, // PublicKey
}).sendAndConfirm(umi);
addLaunchPoolBucketV2
await addLaunchPoolBucketV2(umi, {
genesisAccount, // PublicKey
baseMint, // PublicKey
baseTokenAllocation, // bigint - tokens for this bucket
depositStartCondition, // TimeCondition
depositEndCondition, // TimeCondition
claimStartCondition, // TimeCondition
claimEndCondition, // TimeCondition
minimumDepositAmount, // { amount: bigint } | null
minimumQuoteTokenThreshold, // { amount: bigint } | null - floor, launch fails below it
softCap, // { amount: bigint } | null - REQUIRED, ceiling on quote kept
endBehaviors, // EndBehavior[]
}).sendAndConfirm(umi);
softCap は @metaplex-foundation/genesis 0.42.0 以降、必須引数です。他の Launch Pool 拡張とは異なり、生成されたシリアライザにデフォルト値がないため、ローンチに上限を設けない場合は明示的に softCap: null を渡してください。動作については Launch Pool のソフトキャップを参照してください。
addPresaleBucketV2
await addPresaleBucketV2(umi, {
genesisAccount, // PublicKey
baseMint, // PublicKey
baseTokenAllocation, // bigint
allocationQuoteTokenCap, // bigint - SOL cap (sets price)
depositStartCondition, // TimeCondition
depositEndCondition, // TimeCondition
claimStartCondition, // TimeCondition
claimEndCondition, // TimeCondition
minimumDepositAmount, // bigint | null
depositLimit, // bigint | null - max per user
endBehaviors, // EndBehavior[]
}).sendAndConfirm(umi);
addUnlockedBucketV2
await addUnlockedBucketV2(umi, {
genesisAccount, // PublicKey
baseMint, // PublicKey
baseTokenAllocation, // bigint - usually 0n
recipient, // PublicKey - who can claim
claimStartCondition, // TimeCondition
claimEndCondition, // TimeCondition
}).sendAndConfirm(umi);
depositLaunchPoolV2
await depositLaunchPoolV2(umi, {
genesisAccount, // PublicKey
bucket, // PublicKey
baseMint, // PublicKey
amountQuoteToken, // bigint - lamports
}).sendAndConfirm(umi);
depositPresaleV2
await depositPresaleV2(umi, {
genesisAccount, // PublicKey
bucket, // PublicKey
baseMint, // PublicKey
amountQuoteToken, // bigint - lamports
}).sendAndConfirm(umi);
withdrawLaunchPoolV2
await withdrawLaunchPoolV2(umi, {
genesisAccount, // PublicKey
bucket, // PublicKey
baseMint, // PublicKey
amountQuoteToken, // bigint - lamports
}).sendAndConfirm(umi);
claimLaunchPoolV2
await claimLaunchPoolV2(umi, {
genesisAccount, // PublicKey
bucket, // PublicKey
baseMint, // PublicKey
recipient, // PublicKey
}).sendAndConfirm(umi);
refundLaunchPoolV2
入金ウィンドウが閉じた後に Launch Pool の入金を返金します。金額はプログラムが導出するため、金額の引数はありません。minimumQuoteTokenThreshold に届かなかった場合は入金全額が返金され、softCap を超過した場合は入金者のトークン割り当てを維持したまま超過分のみが返金されます。
await refundLaunchPoolV2(umi, {
genesisAccount, // PublicKey
bucket, // PublicKey
baseMint, // PublicKey
recipient, // PublicKey | Signer - depositor; base token account closed if they sign
}).sendAndConfirm(umi);
署名が必要なのは payer のみのため、入金者に代わって誰でも返金をクランクできます。入金ウィンドウが閉じる前に呼び出すと LaunchPoolNotEnded、下限に達し上限も超過していない状態で呼び出すと LaunchPoolThresholdMet、2 回呼び出すと DepositAlreadyRefunded を返します。
claimPresaleV2
await claimPresaleV2(umi, {
genesisAccount, // PublicKey
bucket, // PublicKey
baseMint, // PublicKey
recipient, // PublicKey
}).sendAndConfirm(umi);
triggerBehaviorsV2
プライマリーbucketに設定された End Behavior を処理し、収集した資金を endBehaviors で指定されたデスティネーションbucketに移動します。
await triggerBehaviorsV2(umi, {
genesisAccount, // PublicKey
primaryBucket, // PublicKey
baseMint, // PublicKey
})
.addRemainingAccounts([/* destination bucket + its quote token account */])
.sendAndConfirm(umi);
revokeV2
ベーストークンのミントおよびフリーズ権限を恒久的に取り消します。
await revokeV2(umi, {
genesisAccount, // PublicKey
baseMint, // PublicKey
baseTokenProgram, // PublicKey - required, e.g. SPL_TOKEN_PROGRAM_ID from mpl-toolbox
revokeMintAuthority, // boolean
revokeFreezeAuthority, // boolean
padding: Array(5).fill(0), // required, no default
}).sendAndConfirm(umi);
PDAヘルパー
| 関数 | シード |
|---|---|
| findGenesisAccountV2Pda() | baseMint, genesisIndex |
| findLaunchPoolBucketV2Pda() | genesisAccount, bucketIndex |
| findPresaleBucketV2Pda() | genesisAccount, bucketIndex |
| findUnlockedBucketV2Pda() | genesisAccount, bucketIndex |
| findLaunchPoolDepositV2Pda() | bucket, recipient |
| findPresaleDepositV2Pda() | bucket, recipient |
const [genesisAccountPda] = findGenesisAccountV2Pda(umi, { baseMint: mint.publicKey, genesisIndex: 0 });
const [bucketPda] = findLaunchPoolBucketV2Pda(umi, { genesisAccount: genesisAccountPda, bucketIndex: 0 });
const [depositPda] = findLaunchPoolDepositV2Pda(umi, { bucket: bucketPda, recipient: wallet });
フェッチ関数
Genesisアカウント
Genesisアカウントはローンチタイプを含むトップレベルのローンチ状態を保存します。バックエンドクランクがsetLaunchTypeV2インストラクションを介して作成後にオンチェーンでlaunchTypeフィールドを設定するため、クランクが処理するまで値はUninitialized(0)のままの場合があります。
| 関数 | 戻り値 |
|---|---|
| fetchGenesisAccountV2() | Genesisアカウントの状態(存在しない場合はエラーをスロー) |
| safeFetchGenesisAccountV2() | Genesisアカウントの状態またはnull |
| fetchGenesisAccountV2FromSeeds() | PDAシード(baseMint、genesisIndex)で取得 |
| safeFetchGenesisAccountV2FromSeeds() | 上記と同じ、存在しない場合はnullを返す |
| fetchAllGenesisAccountV2() | 複数のGenesisアカウントを一括取得 |
import {
fetchGenesisAccountV2,
fetchGenesisAccountV2FromSeeds,
findGenesisAccountV2Pda,
LaunchType,
} from '@metaplex-foundation/genesis';
// PDAアドレスで取得
const [genesisAccountPda] = findGenesisAccountV2Pda(umi, {
baseMint: mintAddress,
genesisIndex: 0,
});
const account = await fetchGenesisAccountV2(umi, genesisAccountPda);
console.log(account.data.launchType); // 0 = Uninitialized, 3 = LaunchPoolV1
// シードから直接取得
const account2 = await fetchGenesisAccountV2FromSeeds(umi, {
baseMint: mintAddress,
genesisIndex: 0,
});
// ローンチタイプの確認
if (account2.data.launchType === LaunchType.LaunchPoolV1) {
console.log('This is a launch pool');
}
Genesisアカウントのフィールド: authority, baseMint, quoteMint, totalSupplyBaseToken, totalAllocatedSupplyBaseToken, totalProceedsQuoteToken, fundingMode, launchType, bucketCount, finalized
GPAビルダー — ローンチタイプで照会
getGenesisAccountV2GpaBuilder()を使用して、オンチェーンフィールドでフィルタリングされた全Genesisアカウントを照会します。SolanaのバイトレベルフィルターによるgetProgramAccounts RPCメソッドを使用して効率的な検索を行います。
import {
getGenesisAccountV2GpaBuilder,
LaunchType,
} from '@metaplex-foundation/genesis';
// すべての Launch Pool ローンチを取得
const launchpools = await getGenesisAccountV2GpaBuilder(umi)
.whereField('launchType', LaunchType.LaunchPoolV1)
.getDeserialized();
// 複数フィールドでフィルタリング
const finalizedLaunchpools = await getGenesisAccountV2GpaBuilder(umi)
.whereField('launchType', LaunchType.LaunchPoolV1)
.whereField('finalized', true)
.getDeserialized();
for (const account of launchpools) {
console.log(account.publicKey, account.data.baseMint, account.data.launchType);
}
launchTypeはローンチ作成後にバックエンドクランクによって遡及的に設定されます。最近作成されたローンチは、クランクが処理するまでLaunchType.Uninitialized(0)を表示する場合があります。
バケットと入金
| 関数 | 戻り値 |
|---|---|
| fetchLaunchPoolBucketV2() | バケットの状態(存在しない場合はエラーをスロー) |
| safeFetchLaunchPoolBucketV2() | バケットの状態またはnull |
| fetchPresaleBucketV2() | バケットの状態(存在しない場合はエラーをスロー) |
| safeFetchPresaleBucketV2() | バケットの状態またはnull |
| fetchLaunchPoolDepositV2() | 入金の状態(存在しない場合はエラーをスロー) |
| safeFetchLaunchPoolDepositV2() | 入金の状態またはnull |
| fetchPresaleDepositV2() | 入金の状態(存在しない場合はエラーをスロー) |
| safeFetchPresaleDepositV2() | 入金の状態またはnull |
const bucket = await fetchLaunchPoolBucketV2(umi, bucketPda);
const deposit = await safeFetchLaunchPoolDepositV2(umi, depositPda); // null if not found
バケットの状態フィールド: quoteTokenDepositTotal, weightedQuoteTokenTotal, depositCount, claimCount, refundCount, bucket.baseTokenAllocation, extensions
入金の状態フィールド: amountQuoteToken, weightedQuoteToken, claimed, refunded
型
LaunchPoolV2Extensions
Launch Pool bucket の任意のガードで、bucket.extensions から読み取ります。すべてのフィールドは Umi の Option であるため、値を読み取る前に unwrapOption() を使用するか .__option を確認してください。
{
backendSigner: Option<BackendSigner>;
depositPenalty: Option<LinearBpsScheduleV2>;
withdrawPenalty: Option<LinearBpsScheduleV2>;
bonusSchedule: Option<LinearBpsScheduleV2>;
depositLimit: Option<DepositLimit>; // { limit: bigint }
allowlist: Option<Allowlist>;
claimSchedule: Option<ClaimSchedule>;
minimumDepositAmount: Option<MinimumDepositAmount>; // { amount: bigint }
minimumQuoteTokenThreshold: Option<MinimumQuoteTokenThreshold>; // { amount: bigint } - floor
softCap: Option<SoftCap>; // { amount: bigint } - ceiling
}
拡張は addLaunchPoolBucketV2Extensions() と removeLaunchPoolBucketV2Extensions() で個別に追加・削除でき、LaunchPoolV2ExtensionType でフィールドを選択します。どちらも Genesis Account がファイナライズされた後は拒否されます。
LaunchType
バックエンドクランクがsetLaunchTypeV2インストラクションを介して遡及的に設定するオンチェーンのローンチカテゴリです。
enum LaunchType {
Uninitialized = 0, // クランクによってまだ設定されていない
LaunchPoolV1 = 3, // Launch Pool(比例配分)
}
Metaplex APIでは文字列('launchpool')として返されますが、オンチェーンSDKでは上記の数値列挙型を使用します。
GenesisAccountV2
Genesisローンチのトップレベルオンチェーンアカウントです。トークンミントごと、ローンチインデックスごとに1つのアカウントが存在します。
{
key: Key;
bump: number;
index: number; // Genesisインデックス(通常は0)
finalized: boolean; // finalizeV2()後にtrue
authority: PublicKey; // ローンチ作成者
baseMint: PublicKey; // ローンチされるトークン
quoteMint: PublicKey; // 入金トークン(例:wSOL)
totalSupplyBaseToken: bigint; // トークン総供給量
totalAllocatedSupplyBaseToken: bigint; // バケットに割り当てられた供給量
totalProceedsQuoteToken: bigint; // 収集された総入金額
fundingMode: number; // ファンディングモード(0)
launchType: number; // 0 = 未初期化, 3 = LaunchPoolV1
bucketCount: number; // バケット数
}
アカウントサイズ:136バイト。PDAシード:["genesis_v2", baseMint, genesisIndex]。
TimeCondition
{
__kind: 'TimeAbsolute',
padding: Array(47).fill(0),
time: bigint, // Unix timestamp (seconds)
triggeredTimestamp: null,
}
EndBehavior
{
__kind: 'SendQuoteTokenPercentage',
padding: Array(4).fill(0),
destinationBucket: PublicKey,
percentageBps: number, // 10000 = 100%
processed: false,
}
定数
| 定数 | 値 |
|---|---|
WRAPPED_SOL_MINT | So11111111111111111111111111111111111111112 |
よくあるエラー
| エラー | 原因 |
|---|---|
insufficient funds | 手数料に必要なSOLが不足 |
already initialized | Genesis Accountが既に存在 |
already finalized | ファイナライズ後は変更不可 |
deposit period not active | 入金期間外 |
claim period not active | 請求期間外 |
InvalidSoftCap (221) | softCap.amount が 0 です。{ amount: 0n } ではなく softCap: null を渡してください |
SoftCapBelowThreshold (222) | softCap.amount が minimumQuoteTokenThreshold.amount を下回っています |
LaunchPoolNotEnded | 入金ウィンドウが閉じる前に refundLaunchPoolV2() が呼び出されました |
LaunchPoolThresholdMet (173) | 下限に達し、ソフトキャップも超過していない状態で返金がリクエストされました |
DepositAlreadyRefunded | 同じ入金に対して refundLaunchPoolV2() が 2 回呼び出されました |
FAQ
Umiとは何ですか?なぜ必要ですか?
UmiはMetaplexのSolana向けJavaScriptフレームワークです。トランザクションの構築、署名者の管理、Metaplexプログラムとのやり取りに一貫したインターフェースを提供します。
Genesis SDKをブラウザで使用できますか?
はい。SDKはNode.jsとブラウザの両方の環境で動作します。ブラウザでは、キーペアファイルの代わりにウォレットアダプターを使用して署名を行います。
fetchとsafeFetchの違いは何ですか?
fetchはアカウントが存在しない場合にエラーをスローします。safeFetchは代わりにnullを返すため、アカウントの存在確認に便利です。
トークンのローンチタイプを取得するにはどうすればいいですか?
トークンのミントアドレスを使用してfetchGenesisAccountV2FromSeeds()でGenesisAccountV2アカウントを取得します。launchTypeフィールドは0(未初期化)または3(LaunchPoolV1)を返します。特定のタイプの全ローンチを照会するには、GPAビルダーを使用します。または、Metaplex APIがREST応答で文字列としてローンチタイプを返します。
トランザクションエラーはどのように処理しますか?
sendAndConfirmの呼び出しを try/catch ブロックで囲みます。エラーメッセージで具体的な失敗理由を確認してください。
次のステップ
完全な実装チュートリアルについて:
- はじめに - セットアップと初回ローンチ
- Launch Pool - 比例配分
- Presale - 固定価格販売
