nawangwe / opensea-whitelabel-website-template

An Opensea website template created with Next.js and BaseUI
MIT License
28 stars 6 forks source link

Getting "Error: Failed to validate buy order parameters. Make sure you're on the right network!" when buying assets #12

Closed allenchuang closed 2 years ago

allenchuang commented 2 years ago

I've been trying to buy asset by invoking fulfillOrder in [tokenid].js but I'm getting error:

Error: Failed to validate buy order parameters. Make sure you're on the right network!

seaport creation code:

  const seaport = new OpenSeaPort(provider, {
    networkName: Network.Main, // <-- mainnet
    apiKey: process.env.OPEN_SEA_API, // valid API Key
  });

in initiatePurchase fulfillOrder code:

await seaport.fulfillOrder({
            order: order,
            accountAddress: address,
});

What could be the cause?

allenchuang commented 2 years ago

i figred out why this is the case- i think it is because of the JSON parsing that happens in getServerSideProps: const asset = JSON.parse(JSON.stringify(assetResponse)); causing some property type mismatch when doing the validation on OpenseaPort side.

@nawangwe do you have a work around for this? so far i've just moved the getOrder call directly inside initiatePurchase but now seeing CORS issue 🤦🏻‍♂️

nawangwe commented 2 years ago

@allenchuang i'll get around to this today, it seems that the opensea is library and api require frequent monitoring and I haven't maintained this repo in a while.

allenchuang commented 2 years ago

no worries thanks so much for taking the time to create this repo! I've looked into it a bit, and i found orderToJSON and orderFromJson exported as part of opensea-js.

I'm looking into it as we speak but hope that give you a headstart! also, might worth looking into updating the opensea-js package to a later version, as to which one i'm not sure.

allenchuang commented 2 years ago

also- from their API it seems that you no longer need to use getAsset you can use getOrder function and pass in the returned object to fulfillOrder as updated in their README. Sorry for dumping all this info on you if it's too much, just trying to help the best i can :D

nawangwe commented 2 years ago

No worries @allenchuang I really appreciate the help! As I'm currently tied down with other projects. Feel free to contribute as well. I'll definitely begin maintaining this on a regular basis.

allenchuang commented 2 years ago

sure! If I get to it before you do i'll file a PR for your approval. Cheers! 🙌🏼

allenchuang commented 2 years ago

update: opensea-js is ridiculous to work with- after several hours of digging, i realized that they are rehauling their API but didn't update their SDKs. the orderToJSON and orderFromJSON don't even work in conjunction.

orderToJSON returns camelCaseProps while orderToJSON expects snake_case_props 🤦🏻‍♂️

Based on the little information on OS dev blogs, I think its best to migrate over to ^2.0.2 for now.

https://opensea.io/blog/developers/wyvern-2-3-developer-upgrade-guide/ https://docs.opensea.io/changelog

allenchuang commented 2 years ago

so far i'm working on getting the buy function to work again, but i keep getting errors submitting the transaction, haven't got a working version for PR yet.

What i've done so far

I'm a bit confused because using fetch order API from https://docs.opensea.io/reference/retrieving-orders returns snake_case_props but using getAsset or getOrder from the SDK returns camelCaseProps

so i'm not sure if the way to go is:

testing it rn, will let you know

allenchuang commented 2 years ago

i tried to push a new branch for the API support but i don't have access to the repo, any chance you can give me contributor access?

allenchuang commented 2 years ago

update: i've tried using the fetch approach- but it's giving me the same error as the title states again... Failed to validate buy order parameters. Make sure you're on the right network!

i'm a bit stumped. i can open [WIP] PR and add some comments, you can pull and take a look at teh changes i've done so far, perhaps you can make better progress!

nawangwe commented 2 years ago

noted @allenchuang