@jup-ag/merkle-distributor-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Merkle Distributor SDK

Installing

npm i @jup-ag/merkle-distributor-sdk

How to use

  1. Initialize MerkleDistributor instance
import MerkleDistributor from '@jup-ag/merkle-distributor-sdk';
import { PublicKey } from '@solana/web3.js';
import { AnchorProvider, web3 } from '@coral-xyz/anchor';
import { Connection } from '@solana/web3.js';

const mainnetConnection = new Connection('https://api.mainnet-beta.solana.com');
const mockWallet = new Wallet(new Keypair());
const provider = new AnchorProvider(mainnetConnection, mockWallet, {
  commitment: 'confirmed',
});

const merkleDistributor = new MerkleDistributor(provider, {
  targetToken: new PublicKey(TARGET_TOKEN), // the token to be distributed.
  claimProofEndpoint: 'https://worker.jup.ag/jup-claim-proof',
});
  1. To claim token with MerkleDistributor
const ixs = await merkleDistributor.claimToken(publicKey);
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
let transaction = new Transaction({
  feePayer: publicKey,
  blockhash,
  lastValidBlockHeight,
}).add(...ixs);

transaction = await wallet.signTransaction(transaction);

const rawTransaction = transaction.serialize();
const txid = await connection.sendRawTransaction(rawTransaction, {
  skipPreflight: true,
});
  1. To get claim status of a user
const claimStatus = await merkleDistributor.getClaimStatus(publicKey);
const amount = claimStatus?.amount;
const isClaimed = claimStatus?.isClaimed;

Readme

Keywords

none

Package Sidebar

Install

npm i @jup-ag/merkle-distributor-sdk

Weekly Downloads

210

Version

0.0.3

License

MIT

Unpacked Size

194 kB

Total Files

50

Last publish

Collaborators

  • thimerosa
  • jjsb
  • hjchan
  • arowana
  • siong
  • dicksonp
  • zhengyutay