rarible / sdk

MIT License
83 stars 41 forks source link

createCollection - invalid 'Content-Type' #613

Closed metmos closed 3 days ago

metmos commented 3 months ago

Hi Rarible SDK Team,

I am encountering an error when creating collection from a backend app (node/nest.js).

I can see the transaction was executed successfully on Ethereum Sepolia but the request fails with 400 bad request error. Screenshot 2024-04-07 at 6 52 11 pm

The source code:

      const alchemyProvider = new ethers.providers.JsonRpcProvider(process.env["ETHEREUM_RPC_URL"]);
      const signer = new ethers.Wallet(process.env["ETH_PRIVATE_KEY"], alchemyProvider);
      const sdk = createRaribleSdk(signer, "testnet", { apiKey: process.env["RARIBLE_API_KEY"] });
      const { address, tx } = await sdk.nft.createCollection({
        blockchain: Blockchain.ETHEREUM,
        type: "ERC1155",
        name: "MmApr3",
        symbol: "MmApr3",
        baseURI: "https://ipfs.rarible.com/mmapra",
        contractURI: "https://ipfs.rarible.com/mmapra",
        isPublic: true,
      });

      await tx.wait();

I intercepted the axios log:

Starting Request {
  "url": "https://logging.rarible.com/",
  "method": "post",
  "data": [
    {
      "service": "ethereum-sdk",
      "environment": "testnet",
      "sessionId": "**********",
      "version": "0.13.68-fix.17",
      "web3Address": "**********",
      "ethNetwork": "11155111",
      "apiKey": "************",
      "level": "TRACE",
      "method": "createToken",
      "message": "{\"hash\":\""************",3\",\"data\":\""************",",\"from\":\""************",\",\"to\":\""************",\"}",
      "args": "[\"MmApr3\",\"MmApr3\",\"https://ipfs.rarible.com/mmapra\",\"https://ipfs.rarible.com/mmapra\",\""************",\"]",
      "provider": "ethers",
      "to": "0x166f6180170f438ddc38050a2b708d38c0890956"
    }
  ],
  "headers": {
    "common": {
      "Accept": "application/json, text/plain, */*"
    },
    "delete": {},
    "get": {},
    "head": {},
    "post": {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    "put": {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    "patch": {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  },
  "transformRequest": [
    null
  ],
  "transformResponse": [
    null
  ],
  "timeout": 0,
  "xsrfCookieName": "XSRF-TOKEN",
  "xsrfHeaderName": "X-XSRF-TOKEN",
  "maxContentLength": -1,
  "maxBodyLength": -1
}
Error Response: {
  "data": "error: invalid 'Content-Type'\n",
  "status": 400,
  "headers": {
    "date": "Sun, 07 Apr 2024 08:44:33 GMT",
    "content-length": "30",
    "connection": "keep-alive",
    "cf-cache-status": "DYNAMIC",
    "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=GkIJ1vMm66CK11IQZdCbv9gEHQjY%2F1eJJXyVTj5y%2F1WG3c4z%2FlLV%2BtW9qcSoRb6nanyboD6XywXFv5S%2FDu0X8J%2BrpBne%2FrRKVzBpHWdNR1XgKhnK2cykepoMLF3kh2Q%2BBpyJw%2Bw%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
    "nel": "{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}",
    "strict-transport-security": "max-age=15552000; includeSubDomains; preload",
    "x-content-type-options": "nosniff",
    "server": "cloudflare",
    "cf-ray": "8708bc7c5855a864-SYD"
  }
}

/node_modules/axios/lib/core/createError.js:16
  var error = new Error(message);
              ^
Error: Request failed with status code 400
  /node_modules/axios/lib/adapters/http.js:260:11)
    at IncomingMessage.emit (node:events:526:35)
    at endReadableNT (node:internal/streams/readable:1408:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

Maybe application/x-www-form-urlencoded is not correct but this request was automatically generated by createCollection, so it could be a bug in the SDK code for this case.

I added form-data and node-fetch config as per https://docs.rarible.org/reference/sdk-on-backend but it makes no difference.

Rarible SDK version

    "@rarible/sdk": "^0.13.68-fix.17",
    "ethers": "5.6.2",
    "form-data": "^4.0.0",
    "node-fetch": "^3.3.2",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1",
    "tslib": "2.3.1",
    "web3": "1.5.0",

Please let me know how we can make createCollection work. Thank you!

ex1st0r commented 1 month ago

Hello! It's an error is related to sending logs. Looks like something changed default headers in axios package. You can try to set : axios.defaults.headers.post['Content-Type'] = 'application/json'