2

I'm trying to use Magic Eden API and solana-py to buy an NFT for the listed price. I'm using the instructins/buy_now endpoint to do that. I get an error when trying to buy the NFT. Have been trying to fix that for a few weeks, and I still can't. The part of the code for signing the TX:

account_sign = Keypair.from_secret_key(b58decode("xxxxxx"))
tx_signed = data['txSigned']
txn = Transaction.deserialize(bytes(tx_signed['data']))
txn.sign(account_sign)
await solana_client.send_raw_transaction(txn.serialize())

My error:

sign error: {'code': -32002, 'message': 'Transaction simulation failed: Error processing Instruction 2: custom program error: 0x7d3', 'data': {'accounts': None, 'err': {'InstructionError': [2, {'Custom': 2003}]}, 'logs': ['Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K invoke [1]', 'Program log: Instruction: Deposit', 'Program 11111111111111111111111111111111 invoke [2]', 'Program 11111111111111111111111111111111 success', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K consumed 9465 of 600000 compute units', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K success', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K invoke [1]', 'Program log: Instruction: Buy', 'Program 11111111111111111111111111111111 invoke [2]', 'Program 11111111111111111111111111111111 success', 'Program log: {"price":32000000,"buyer_expiry":0}', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K consumed 26365 of 590535 compute units','Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K success', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K invoke [1]', 'Program log: Instruction: ExecuteSale', 'Program log: AnchorError caused by account: seller_trade_state. Error Code: ConstraintRaw. Error Number: 2003. Error Message: A raw constraint was violated.', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K consumed 23877 of 564170 compute units', 'Program M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K failed: custom program error: 0x7d3'], 'unitsConsumed': 35830}}

The URL I'm sending to the ME API:

https://api-mainnet.magiceden.dev/v2/instructions/buy_now?buyer=ADsE28NEc1hD9ZjocLBGrwARCuK5NTSi7HtwUktNbXD1&seller=D2AxugHdccsxy9KD7sUmZjJnvdgadYw4kptwDKaQPyQ&auctionHouseAddress=E8cU1WiRWjanGxmn96ewBgk9vPTcL6AEZ1t6F6fkgUWe&tokenMint=DefXNy9qma1CgEjFRbbaPjPdFAS1VuEwTY1Lt631zHqC&tokenATA=8LeRMLpcNbvewqNUs22yeP8cNvzod3C5ictURqT722Yj&price=0.01&sellerReferral=autMW8SgBkVYeBgqYiTuJZnkvDZMVU2MHJh9Jh7CSQ2&sellerExpiry=0

ME responds with something similar to this:

{
    "tx":
    {
        "type": "Buffer",
        "data":
        [
            2,
            1,
            9,
            .....
        ]
    },
    "txSigned":
    {
        "type": "Buffer",
        "data":
        [
            2,
            0,
            0,
            .....
        ]
    }
}

What am I doing wrong? Really need your help.

2
  • Have you tried another listing?
    – Arowana
    Commented Aug 10, 2022 at 21:41
  • @Arowana I was checking on 2 collections and have been having the same issue. I tried another one right now and it worked.
    – Maxisy
    Commented Aug 11, 2022 at 9:10

2 Answers 2

1

Here is the documentation: https://api.magiceden.dev/#51aff214-f517-47f6-b27b-66ca49029dbd

First you need to make sure you have an API key as the buy now request requires a bearer token.

Then our working instruction set is:

/instructions/buy-now
buyer=9X2******W35
seller=8dB******QtjZ
tokenMint=H9i******aq1L
tokenATA=7VW******Whg
price=3.5
auctionHouseAddress=E8cU1WiRWjanGxmn96ewBgk9vPTcL6AEZ1t6F6fkgUWe
sellerExpiry:-1

Edit:

The sellerExpiry is incorrect and will return a bad instruction set as I was saying.
I just purchased the example NFT using my example instruction set with the correct dynamic parameters filled in.
enter image description here

6
  • He mentioned he did get a response so of course he has an API key, it is the transaction itself that is failing.
    – Arowana
    Commented Aug 11, 2022 at 8:49
  • yeah, I have the API key and the params are correct. I don't think that the order of the params is meaningful.
    – Maxisy
    Commented Aug 11, 2022 at 8:52
  • @Maxisy The params are not correct. I just purchased your example NFT using the reference instruction set posted. Your sellerExpiry is wrong.
    – Bryon M
    Commented Aug 12, 2022 at 0:24
  • @Arowana Documentation and authorization is good general information. Also the transaction data is incorrect, for good reason.
    – Bryon M
    Commented Aug 12, 2022 at 0:34
  • @BryonM what did you set the sellerExpiry to?
    – Maxisy
    Commented Aug 12, 2022 at 13:37
0

Looking at the actual centralized app listing https://magiceden.io/item-details/DefXNy9qma1CgEjFRbbaPjPdFAS1VuEwTY1Lt631zHqC, the seller, tokenAta, auction house and price you have provided are correct.

During the execute_sale instruction it gives:

"Program log: AnchorError caused by account: seller_trade_state. Error Code: ConstraintRaw. Error Number: 2003. Error Message: A raw constraint was violated."

So it is failing this constraint

https://github.com/metaplex-foundation/metaplex-program-library/blob/master/auction-house/program/src/execute_sale/mod.rs#L124-L138

It doesn't look like you are doing anything wrong and this must be a bug on ME side or in the auction house code.

5
  • I think you need a Api key from magiceden to buy something. I’m not a experienced dev but this could be the problem right?
    – JasOn
    Commented Aug 11, 2022 at 1:19
  • I do have the API key
    – Maxisy
    Commented Aug 11, 2022 at 8:52
  • 1
    It looks like it's a problem on ME's side, since my code worked well on another collection.
    – Maxisy
    Commented Aug 11, 2022 at 9:18
  • Ah then okay sorry
    – JasOn
    Commented Aug 11, 2022 at 10:20
  • It is not an issue with ME. It is the parameters.
    – Bryon M
    Commented Aug 12, 2022 at 0:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.