UNPKG

@magiceden/magiceden-sdk

Version:

A TypeScript SDK for interacting with Magic Eden's API across multiple chains.

94 lines (93 loc) 3.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MagicEdenSDK = void 0; const types_1 = require("./types"); const client_1 = require("./client"); const solana_1 = require("./wallet/solana"); const viemWalletProvider_1 = require("./wallet/evm/viemWalletProvider"); /** * Magic Eden SDK V1 implementation */ class MagicEdenSDKV1 { /** * Creates a new Magic Eden API client for Solana * @param apiKey Your Magic Eden API key * @param walletProvider The wallet provider to use * @param clientConfig Additional client configuration * @returns A new Magic Eden API client for Solana */ static createSolanaClient(apiKey, walletProvider, clientConfig = {}) { if (!apiKey) { throw new Error('API key is required to create a Magic Eden client'); } return new client_1.MagicEdenClient({ apiKey, ...clientConfig, chain: types_1.ChainType.SOLANA, wallet: walletProvider, }); } /** * Creates a new Magic Eden API client for Solana using a keypair * @param apiKey Your Magic Eden API key * @param keypair The Solana keypair to use for the client * @param options Optional configuration * @param options.rpcUrl Custom Solana RPC URL (defaults to public endpoint if not provided) * @param options.clientConfig Additional client configuration * @returns A new Magic Eden API client for Solana */ static createSolanaKeypairClient(apiKey, keypair, options) { const rpcUrl = options?.rpcUrl || 'https://api.mainnet-beta.solana.com'; const walletProvider = new solana_1.SolanaKeypairWalletProvider({ secretKey: keypair.secretKey, rpcEndpoint: rpcUrl, }); return this.createSolanaClient(apiKey, walletProvider, options?.clientConfig); } /** * Creates a new Magic Eden API client for an EVM blockchain * @param apiKey Your Magic Eden API key * @param walletProvider The wallet provider to use * @param clientConfig Additional client configuration * @returns A new Magic Eden API client for an EVM blockchain */ static createEvmClient(apiKey, walletProvider, clientConfig = {}) { if (!apiKey) { throw new Error('API key is required to create a Magic Eden client'); } return new client_1.MagicEdenClient({ apiKey, ...clientConfig, chain: types_1.ChainType.EVM, wallet: walletProvider, }); } /** * Creates a new Magic Eden API client for an EVM blockchain using a private key * @param apiKey Your Magic Eden API key * @param privateKey The private key to use for the client * @param blockchain The blockchain to use * @param options Optional configuration * @param options.clientConfig Additional client configuration * @param options.walletOptions Wallet options * @returns A new Magic Eden API client for an EVM blockchain */ static createViemEvmClient(apiKey, privateKey, blockchain, options) { const walletProvider = new viemWalletProvider_1.ViemWalletProvider({ privateKey, blockchain, options: options?.walletOptions, }); return this.createEvmClient(apiKey, walletProvider, options?.clientConfig); } } /** * Magic Eden SDK */ class MagicEdenSDK { } exports.MagicEdenSDK = MagicEdenSDK; /** * Magic Eden SDK V1 API methods */ MagicEdenSDK.v1 = MagicEdenSDKV1;