π€οΈPurchase an NFT with any token on any chain
Submit your intents and receive all possible solutions for the best execution route.
// Example: Purchase an NFT using ETH
async function purchaseNFT() {
try {
const result = await legoClient.MagicEden.SwapForNFT({
items: [{
address: '0x7E0b0363804C6C79AAb9aB51850bF8F3D561f868', // NFT contract address
tokenId: '42' // The NFT token ID you want to purchase
}],
token: {
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH address
decimals: 18,
chainId: 1 // Ethereum mainnet
},
userAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e' // Your wallet address
});
if (result.status) {
console.log('Success! Transaction steps:', result.data.steps);
// Execute the transaction steps...
} else {
console.error('Failed to fetch data:', result.error);
}
} catch (error) {
console.error('Error:', error);
}
}Available parameters
Parameter
Description
Type
Last updated