Magic Eden SDK
A TypeScript SDK for interacting with Magic Eden's API across multiple chains (Solana and EVM-compatible blockchains).
BETA NOTICE: This SDK is currently in beta. The endpoints and methods documented in this README have been tested, but still may contain bugs or other issues. API signatures and parameters may still change before the stable release.
Installation
npm install @magiceden/magiceden-sdk
Getting Started
The Magic Eden SDK provides a unified interface for interacting with NFTs across different blockchains. Here's how to get started:
Initialize the SDK
import { MagicEdenSDK } from '@magiceden/magiceden-sdk';
Solana SDK
Initialization (Solana)
import { MagicEdenSDK } from '@magiceden/magiceden-sdk';
import { Keypair } from '@solana/web3.js';
import { Blockchain } from '@magiceden/magiceden-sdk';
const solanaKeypair = Keypair.generate();
const solanaClient = MagicEdenSDK.v1.createSolanaKeypairClient(
'YOUR_API_KEY',
solanaKeypair,
{
rpcUrl: 'SOLANA_RPC_URL'
}
);
Listing an NFT (Solana)
const listResult = await solanaClient.nft.list({
token: '7um9nU7CDhss1fepFMRpjHhB3qm7exfQf47cdbRSUGuS',
price: '1000000000',
});
console.log('Listing created:', listResult);
Canceling a Listing (Solana)
const cancelResult = await solanaClient.nft.cancelListing({
token: '7um9nU7CDhss1fepFMRpjHhB3qm7exfQf47cdbRSUGuS',
price: '1000000000',
});
console.log('Listing canceled:', cancelResult);
Making an Offer (Solana)
const offerResult = await solanaClient.nft.makeItemOffer({
token: '7YCrxt8Ux9dym832BKLDQQWJYZ2uziXgbF6cYfZaChdP',
price: '900000',
});
console.log('Offer made:', offerResult);
Canceling an Offer (Solana)
const cancelOfferResult = await solanaClient.nft.cancelItemOffer({
token: '7YCrxt8Ux9dym832BKLDQQWJYZ2uziXgbF6cYfZaChdP',
price: '900000',
});
console.log('Offer canceled:', cancelOfferResult);
Taking an Offer (Selling to an Offer)
const takeOfferResult = await solanaClient.nft.takeItemOffer({
token: '7um9nU7CDhss1fepFMRpjHhB3qm7exfQf47cdbRSUGuS',
buyer: '4H2bigFBsMoTAwkn7THDnThiRQuLCrFDGUWHf4YDpf14',
price: '1500000',
newPrice: '1000000',
});
console.log('Offer accepted:', takeOfferResult);
Buying an NFT (Solana)
const buyResult = await solanaClient.nft.buy({
token: '7um9nU7CDhss1fepFMRpjHhB3qm7exfQf47cdbRSUGuS',
seller: '4H2bigFBsMoTAwkn7THDnThiRQuLCrFDGUWHf4YDpf14',
price: '1500000',
});
console.log('Purchase completed:', buyResult);
Transferring an NFT (Solana)
const transferResult = await solanaClient.nft.transfer({
token: 'BxRLKzJVJzyNBRqE6bnhqthbHGMSvyv9GotKihwX6LqJ',
to: '4H2bigFBsMoTAwkn7THDnThiRQuLCrFDGUWHf4YDpf14',
isCompressed: true,
});
console.log('Transfer completed:', transferResult);
Creating a Launchpad (Solana)
Creating a launchpad on Solana is a two-step process. The steps are as follows:
- Create the launchpad with
createLaunchpad.
- Publish the launchpad with
publishLaunchpad.
const launchpadResult = await client.nft.createLaunchpad({
chain: Blockchain.SOLANA,
protocol: SolProtocolType.METAPLEX_CORE,
creator: walletAddress,
name: 'TestCollection',
symbol: 'TEST',
description: 'This is a test collection created with the Magic Eden self-serve API',
nftMetadataUrl: 'https://bafybeic3rs6wmnnhqachwxsiizlblignek6aitc5b3ooenhhtkez3onmwu.ipfs.w3s.link',
royaltyBps: 500,
royaltyRecipients: [{ address: walletAddress, share: 100 }],
payoutRecipient: walletAddress,
social: {
discordUrl: 'https://discord.gg/magiceden',
twitterUsername: 'magiceden',
externalUrl: 'https://magiceden.io',
},
mintStages: {
maxSupply: 10000,
stages: [
{
kind: MintStageKind.Allowlist,
price: {
currency: {
chain: Blockchain.SOLANA,
assetId: 'So11111111111111111111111111111111111111112',
},
raw: '1',
},
startTime: '2025-03-20T00:00:00.000Z',
endTime: '2025-03-27T00:00:00.000Z',
walletLimit: 2,
allowlist: [
walletAddress,
"5FHwkrdxkrR7zKy1jHmqh5uWyKj1ZbM7PKhRgw7F8Z8K",
"8HXhDbwLVeS7neCC93dYeM9LCokRMSbSw2q9ofsPRgWi"
],
},
{
kind: MintStageKind.Public,
price: {
currency: {
chain: Blockchain.SOLANA,
assetId: 'So11111111111111111111111111111111111111112',
},
raw: '1',
},
startTime: '2025-03-28T00:00:00.000Z',
endTime: '2030-03-30T00:00:00.000Z',
walletLimit: 10
},
],
},
isOpenEdition: false,
});
console.log('Launchpad created successfully:', launchpadResult);
Updating a Launchpad (Solana)
const updateResult = await client.nft.updateLaunchpad({
chain: Blockchain.SOLANA,
protocol: SolProtocolType.METAPLEX_CORE,
collectionId: '<COLLECTION_ID>',
owner: walletAddress,
payer: walletAddress,
symbol: 'TEST2',
newSymbol: 'TEST',
candyMachineId: '<CANDY_MACHINE_ID>',
name: 'TestCollection',
payoutRecipient: walletAddress,
royaltyRecipients: [{ address: walletAddress, share: 100 }],
});
console.log('Launchpad updated successfully!', updateResult);
Minting an NFT (Solana)
const mintResult = await client.nft.mint({
chain: Blockchain.SOLANA,
collectionId: '22zxgVwS7cXkTRfvFgERnN5KZpLgukQXAoauNkHtghX2',
nftAmount: 1,
kind: MintStageKind.Public,
candyMachineId: 'iQU3uT6WnnYkCXqXreXm2ysihoj8WGXk5GJtczcos6a',
symbol: 'TEST',
});
console.log('Mint completed successfully!', mintResult);
Complete Example (Solana)
import { MagicEdenSDK } from '@magiceden/magiceden-sdk';
import { Keypair } from '@solana/web3.js';
import { Blockchain, SolProtocolType, MintStageKind } from '@magiceden/magiceden-sdk';
import bs58 from 'bs58';
const apiKey = 'YOUR_API_KEY';
const keypair = Keypair.fromSecretKey(
bs58.decode('YOUR_PRIVATE_KEY')
);
const client = MagicEdenSDK.v1.createSolanaKeypairClient(apiKey, keypair, {
rpcUrl: 'https://mainnet.helius-rpc.com/?api-key=YOUR_HELIUS_API_KEY',
});
async function listNFT() {
try {
await client.nft.list({
token: '7um9nU7CDhss1fepFMRpjHhB3qm7exfQf47cdbRSUGuS',
price: '1000000000',
});
console.log('NFT listed successfully!');
} catch (error) {
console.error('Error listing NFT:', error);
}
}
listNFT();
EVM SDK (Ethereum, Polygon, Base, etc)
Initialization (EVM)
import { MagicEdenSDK } from '@magiceden/magiceden-sdk';
import { Blockchain } from '@magiceden/magiceden-sdk';
const evmClient = MagicEdenSDK.v1.createViemEvmClient(
'YOUR_API_KEY',
'0xYOUR_PRIVATE_KEY',
Blockchain.BASE
);
Listing an NFT (EVM)
const listResult = await client.nft.list({
chain: Blockchain.BASE,
params: [{
token: '0x949de1b4d4cc4a8e63b7565b6dc525d8eb5dd15a:0',
price: '10000000012',
}]
});
console.log('List completed successfully!', listResult);
Canceling a Listing (EVM)
const cancelResult = await client.nft.cancelListing({
chain: Blockchain.BASE,
orderIds: ['0xc34124b0276f92ca985c2b7e25e9a5c3164c5aa45a2fe1ff1ac6c33b4665649c'],
});
console.log('Listing canceled successfully!', cancelResult);
Making an Offer (EVM)
const makeItemOfferResponse = await client.nft.makeItemOffer({
chain: Blockchain.BASE,
params: [{
token: '0x1195cf65f83b3a5768f3c496d3a05ad6412c64b7:304163',
price: '9000',
}]
});
console.log('Offer made successfully!', makeItemOfferResponse);
Canceling an Offer (EVM)
const cancelOfferResult = await client.nft.cancelItemOffer({
chain: Blockchain.BASE,
orderIds: ['0x18fc51e19bc96bc07b9bdd804eb055a691e46e3cd2c37a5d7e53daedebae70c4'],
});
console.log('Offer canceled successfully!', cancelOfferResult);
Taking an Offer (EVM)
const takeOfferResult = await client.nft.takeItemOffer({
chain: Blockchain.BASE,
items: [{
token: '0x949de1b4d4cc4a8e63b7565b6dc525d8eb5dd15a:0',
quantity: 1,
orderId: '0x18fc51e19bc96bc07b9bdd804eb055a691e46e3cd2c37a5d7e53daedebae70c4',
}],
});
console.log('Offer accepted successfully!', takeOfferResult);
Buying an NFT (EVM)
const buyResult = await client.nft.buy({
chain: Blockchain.BASE,
items: [{
token: '0x1c55ec22ec5083dd0937b9590df4f2629ee43fe9:3030',
quantity: 1,
}],
});
console.log('Buy completed successfully!', buyResult);
Transferring an NFT (EVM)
const transferResult = await client.nft.transfer({
chain: Blockchain.BASE,
items: [{
token: '0x1c55ec22ec5083dd0937b9590df4f2629ee43fe9:3030',
quantity: 1,
}],
to: '0x1fDcfcdeE9e8fA32D95b9648a30E5Cb8C6C7197b',
});
console.log('Transfer completed successfully!', transferResult);
Creating a Launchpad (EVM)
const launchpadResult = await client.nft.createLaunchpad({
chain: Blockchain.BASE,
protocol: EvmProtocolType.ERC1155,
creator: walletAddress,
name: 'TestCollection',
symbol: 'TEST',
description: 'This is a test collection created with the Magic Eden self-serve API',
nftMetadataUrl: 'https://bafybeic3rs6wmnnhqachwxsiizlblignek6aitc5b3ooenhhtkez3onmwu.ipfs.w3s.link',
royaltyBps: 500,
royaltyRecipients: [{ address: walletAddress, share: 100 }],
payoutRecipient: walletAddress,
mintStages: {
tokenId: 0,
maxSupply: 10000,
walletLimit: 10,
stages: [
{
kind: MintStageKind.Allowlist,
price: {
currency: {
chain: Blockchain.BASE,
assetId: '0x0000000000000000000000000000000000000000',
},
raw: '1',
},
startTime: '2025-03-20T00:00:00.000Z',
endTime: '2025-03-27T00:00:00.000Z',
walletLimit: 2,
allowlist: [
walletAddress,
'0x1fDcfcdeE9e8fA32D95b9648a30E5Cb8C6C7197b',
'0x43B6BF3DD080D5a7055Ee6785a6f1d4Ba54fa09d',
],
},
{
kind: MintStageKind.Public,
price: {
currency: {
chain: Blockchain.BASE,
assetId: '0x0000000000000000000000000000000000000000',
},
raw: '1',
},
startTime: '2025-03-28T00:00:00.000Z',
endTime: '2030-03-30T00:00:00.000Z',
walletLimit: 10,
},
],
},
});
console.log('Launchpad created successfully!', launchpadResult);
Updating a Launchpad (EVM)
const updateResult = await client.nft.updateLaunchpad({
chain: Blockchain.BASE,
protocol: EvmProtocolType.ERC1155,
tokenId: 0,
collectionId: '0x949de1b4d4cc4a8e63b7565b6dc525d8eb5dd15a',
owner: walletAddress,
name: 'TestCollection2',
payoutRecipient: walletAddress,
});
console.log('Launchpad updated successfully!', updateResult);
Minting an NFT (EVM)
const mintResult = await evmClient.nft.mint({
chain: Blockchain.BASE,
collectionId: '0x949de1b4d4cc4a8e63b7565b6dc525d8eb5dd15a',
nftAmount: 1,
tokenId: 0,
kind: MintStageKind.Public,
protocol: EvmProtocolType.ERC1155,
});
console.log('Mint completed:', mintResult);
Complete Example
import { MagicEdenSDK } from '@magiceden/magiceden-sdk';
import { Blockchain, EvmProtocolType, MintStageKind } from '@magiceden/magiceden-sdk';
const apiKey = 'YOUR_API_KEY';
const privateKey = '0xYOUR_PRIVATE_KEY';
const evmClient = MagicEdenSDK.v1.createViemEvmClient(
apiKey,
privateKey,
Blockchain.BASE
);
async function mintNFT() {
try {
const result = await evmClient.nft.mint({
chain: Blockchain.BASE,
collectionId: '0x949de1b4d4cc4a8e63b7565b6dc525d8eb5dd15a',
nftAmount: 1,
tokenId: 0,
kind: MintStageKind.Public,
protocol: EvmProtocolType.ERC1155,
});
console.log('NFT minted successfully!', result);
} catch (error) {
console.error('Error minting NFT:', error);
}
}
mintNFT();