0

I don't understand what I'm doing wrong. Trying for a long time on different nfts and still no success, always gets err: 'invalid collection'. But if I'm correct according to official docs it's almost same, right? Can someone please explain what should I replace or adjust?

import Web3 from "@solana/web3.js";
import * as splToken from "@solana/spl-token";
import axios from "axios";

(async () => {
  const bearerToken = "my_me_api_token";
  const secretKey = Uint8Array.from([my_solana_private_key]);
  const keypair = Web3.Keypair.fromSecretKey(secretKey);
  const connection = new Web3.Connection(
    Web3.clusterApiUrl("mainnet-beta"),
    "confirmed"
  );

  const tokenMintAddress = "HtLx6jvwitsenU6ygGbNrpNAMs86xrDfVLMNny48Ho2q";
  const sellerPublicKey = "628zeEqoK3AJ9epWKo5YdL2LJHQtYV6MzFibkE7j4fyQ"; 

  const tokenMint = new Web3.PublicKey(tokenMintAddress);
  const buyerPublicKey = keypair.publicKey;
  const tokenATA = await splToken.getAssociatedTokenAddress(
    tokenMint,
    buyerPublicKey,
    false,
    splToken.TOKEN_PROGRAM_ID,
    splToken.ASSOCIATED_TOKEN_PROGRAM_ID
  );

  try {
    const res = await axios.get(
      "https://api-mainnet.magiceden.dev/v2/instructions/buy",
      {
        params: {
          buyer: keypair.publicKey.toBase58(),
          seller: sellerPublicKey,
          auctionHouseAddress: "E8cU1WiRWjanGxmn96ewBgk9vPTcL6AEZ1t6F6fkgUWe",
          tokenMint: tokenMintAddress,
          tokenATA: tokenATA.toBase58(),
          price: 0.0003,
          buyerExpiry: 0,
          sellerExpiry: -1,
          buyerCreatorRoyaltyPercent: 0
        },
        headers: { Authorization: "Bearer " + bearerToken },
      }
    );

    const txSigned = res.data.txSigned;
    const txn = Web3.Transaction.from(Buffer.from(txSigned, 'base64'));
    const signature = await Web3.sendAndConfirmTransaction(connection, txn, [keypair]);

    console.log("Transaction signature:", signature);
  } catch (err) {
    console.error("Error:", err);
  }
})();

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.