Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opensea-js v6.1.1 does not allow me to create orders on MATIC. Any ETA? #1076

Closed
munimdev opened this issue Jul 9, 2023 · 5 comments
Closed

Comments

@munimdev
Copy link

munimdev commented Jul 9, 2023

Tried the new version to crate an offer, it's throwing this error Error: Creating orders on matic not yet supported by the SDK.

My code:

const { ethers } = require("ethers");
const { OpenSeaSDK, Chain } = require("opensea-js");

// This example provider won't let you make transactions, only read-only calls:
const provider = new ethers.providers.JsonRpcProvider(
  "https://mainnet.infura.io"
);

const wallet = new ethers.Wallet(
  "<key>",
  provider
);

const openseaSDK = new OpenSeaSDK(provider, {
  chain: Chain.Polygon,
  apiKey: "<API>",
});

// Token ID and smart contract address for a non-fungible token:
const { tokenId, tokenAddress } = {
  tokenId: "<id>",
  tokenAddress: "<address>",
};
// The offerer's wallet address:
const accountAddress = "<account address>";

const main = async () => {
  const offer = await openseaSDK.createBuyOrder({
    asset: {
      tokenId,
      tokenAddress,
    },
    accountAddress,
    // Value of the offer, in units of the payment token (or wrapped ETH if none is specified):
    startAmount: 1.2,
  });

  console.log("Offer created: ", offer);
};

main();

Any ETA on when we can expect to create offers? And is there currently a way to do this with the API? A working example would be very much appreciated.

Originally posted by @munimdev in #1062 (comment)

@ryanio
Copy link
Collaborator

ryanio commented Jul 9, 2023

Are you sure you're on v6.1.1? I would delete your node_modules and reinstall. What happens if you execute the cmd cat node_modules/opensea-js/package.json

@ryanio
Copy link
Collaborator

ryanio commented Jul 9, 2023

You also have to pass the wallet to the 4th constructor arg of the library

@munimdev
Copy link
Author

Are you sure you're on v6.1.1? I would delete your node_modules and reinstall. What happens if you execute the cmd cat node_modules/opensea-js/package.json

I'm on Windows but here's the contents of that file:

{
  "name": "opensea-js",
  "version": "6.1.1",
  "description": "JavaScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data!",
  "license": "MIT",
  "author": "OpenSea Developers",
  "homepage": "https://docs.opensea.io/reference/api-overview",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ProjectOpenSea/opensea-js.git"
  },
  "bugs": {
    "url": "https://github.com/ProjectOpenSea/opensea-js/issues"
  },
  "main": "lib/index.js",
  "files": [
    "lib",
    "src"
  ],
  "scripts": {
    "abi-type-gen": "typechain --target=ethers-v5 src/abi/*.json --out-dir=src/typechain/contracts",
    "build": "npm run abi-type-gen && tsc -p tsconfig.build.json && npm run bundle",
    "bundle": "browserify lib/index.js -o lib/bundle.js",
    "check-types": "tsc --noEmit --project tsconfig.json",
    "coverage-report": "nyc report --reporter=lcov",
    "docs-build": "typedoc --out docs src/index.ts",
    "eslint:check": "eslint . --max-warnings 0 --ext .js,.ts",
    "eslint:fix": "npm run eslint:check -- --fix",
    "postinstall": "husky install || exit 0",
    "lint": "concurrently \"npm run check-types\" \"npm run prettier:check\" \"npm run eslint:check\"",
    "prepare": "npm run build",
    "prettier:check": "prettier --check .",
    "prettier:check:package.json": "prettier-package-json --list-different",
    "prettier:fix": "prettier --write .",
    "test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' TS_NODE_TRANSPILE_ONLY=true nyc mocha -r ts-node/register test/**/*.spec.ts --exclude test/integration/**/*.ts --timeout 15000",
    "test:integration": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' TS_NODE_TRANSPILE_ONLY=true nyc mocha -r ts-node/register -r dotenv/config test/integration/**/*.spec.ts --timeout 25000"
  },
  "types": "lib/index.d.ts",
  "dependencies": {
    "@opensea/seaport-js": "^2.0.0",
    "ethers": "^5.7.2"
  },
  "devDependencies": {
    "@typechain/ethers-v5": "^11.0.0",
    "@types/chai": "4.3.5",
    "@types/chai-as-promised": "^7.1.5",
    "@types/mocha": "^10.0.0",
    "@types/node": "^18.0.0",
    "@typescript-eslint/eslint-plugin": "^5.7.0",
    "@typescript-eslint/parser": "^5.7.0",
    "browserify": "^17.0.0",
    "chai": "4.3.7",
    "chai-as-promised": "^7.1.1",
    "concurrently": "8.2.0",
    "confusing-browser-globals": "^1.0.11",
    "dotenv": "^16.0.3",
    "eslint": "^8.4.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-import-resolver-typescript": "^3.0.0",
    "eslint-plugin-import": "^2.25.3",
    "eslint-plugin-prettier": "^4.0.0",
    "husky": "^8.0.3",
    "lint-staged": "^13.2.2",
    "mocha": "^10.0.0",
    "nyc": "^15.1.0",
    "prettier": "2.8.8",
    "prettier-package-json": "2.8.0",
    "ts-node": "10.9.1",
    "typechain": "^8.0.0",
    "typedoc": "^0.24.0",
    "typescript": "5.1.3"
  },
  "keywords": [
    "collectibles",
    "crypto",
    "ethereum",
    "javascript",
    "marketplace",
    "nft",
    "node",
    "non-fungible-tokens",
    "project-opensea",
    "sdk",
    "smart-contracts"
  ],
  "engines": {
    "node": ">=16.0.0"
  },
  "lint-staged": {
    "package.json": [
      "prettier-package-json --write"
    ],
    "**/*.{ts,tsx,js,jsx,html,md,mdx,yml,json}": [
      "prettier --write"
    ],
    "**/*.{ts,tsx,js,jsx}": [
      "eslint --cache --fix"
    ]
  },
  "nyc": {
    "exclude": [
      "src/utils/tokens/**/*.ts",
      "src/typechain"
    ]
  }
}

You also have to pass the wallet to the 4th constructor arg of the library

Also, tried that. Getting the same error:

path\node_modules\opensea-js\lib\sdk.js:208
                throw new Error(`Creating orders on ${this.chain} not yet supported by the SDK.`);
                      ^

Error: Creating orders on matic not yet supported by the SDK.
    at OpenSeaSDK.<anonymous> (path\node_modules\opensea-js\lib\sdk.js:208:23)
    at Generator.next (<anonymous>)
    at path\node_modules\opensea-js\lib\sdk.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (path\node_modules\opensea-js\lib\sdk.js:4:12)
    at OpenSeaSDK.createBuyOrder (path\node_modules\opensea-js\lib\sdk.js:202:16)
    at main (path\new.js:32:34)
    at Object.<anonymous> (path\new.js:45:1)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)

My code:

const { ethers } = require("ethers");
const { OpenSeaSDK, Chain } = require("opensea-js");

// This example provider won't let you make transactions, only read-only calls:
const provider = new ethers.providers.JsonRpcProvider(
  "https://mainnet.infura.io"
);

const wallet = new ethers.Wallet(
  "<Private Key>",
  provider
);

const openseaSDK = new OpenSeaSDK(
  provider,
  {
    chain: Chain.Polygon,
    apiKey: "<OpenSea API key>",
  },
  wallet
);

// Token ID and smart contract address for a non-fungible token:
const { tokenId, tokenAddress } = {
  tokenId: "19766",
  tokenAddress: "0xdb46d1dc155634fbc732f92e853b10b288ad5a1d",
};
// The offerer's wallet address:
const accountAddress = "<Public Address of my wallet>";

const main = async () => {
  const offer = await openseaSDK.createBuyOrder({
    asset: {
      tokenId,
      tokenAddress,
    },
    accountAddress,
    // Value of the offer, in units of the payment token (or wrapped ETH if none is specified):
    startAmount: 1.2,
  });

  console.log("Offer created: ", offer);
};

main();

And my own package.json file:

{
  "name": "opensea-6.1.1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ethers": "^5.7.2",
    "opensea-js": "^6.1.1"
  }
}

@munimdev
Copy link
Author

munimdev commented Jul 10, 2023

Just checked the source code for opensea-js/lib/sdk.js. The issue is because of these lines of code:

//TODO: Make this function multichain compatible
if (this.chain != types_1.Chain.Mainnet && this.chain != types_1.Chain.Goerli) {
    throw new Error(`Creating orders on ${this.chain} not yet supported by the SDK.`);
}

Reference: https://github.com/ProjectOpenSea/opensea-js/blob/main/src/sdk.ts#L356-L361

@thenerdassassin
Copy link
Contributor

Thanks, fixing this in patch version 6.1.2 which will get published this morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants