1

I am trying to call an async function in a POST handler.

The function I am trying to call is as follows (this code works):

const seaport = require("./seaport.js");

// This function creates a fixed price sell order (FPSO)
async function createFPSO(ownerAddress, contractAddress, tokenId, startAmount, expirationTime = 0) {
  const fixedPriceSellOrder = await seaport.createSellOrder({
    asset: {
      tokenId: tokenId,
      tokenAddress: contractAddress,
    },
    startAmount: startAmount,
    expirationTime: expirationTime,
    accountAddress: ownerAddress,
  });
  console.log(`Successfully created a fixed-price sell order! ${fixedPriceSellOrder.asset.openseaLink}\n`);
}

createFPSO(MY_ADDRESS, NFT_CONTRACT_ADDRESS, "2", 0.01);

Since the code above works, I now try to transfer it to a POST handler, as follows:

const express = require('express');
const app = express();
app.use(express.json());
const seaport = require("./seaport.js");

app.post('/create/fixedprice', async (req, res, next)=> {
  try {
    const fixedPriceSellOrder = await seaport.createSellOrder({
      asset: {
        tokenId: req.body.tokenId,
        tokenAddress: req.body.contractAddress,
      },
      startAmount: req.body.startAmount,
      expirationTime: req.body.expirationTime,
      accountAddress: req.body.ownerAddress,
    });
    console.log(`Successfully created a fixed-price sell order! ${fixedPriceSellOrder.asset.openseaLink}\n`);
    res.send(fixedPriceSellOrder);
  } catch (error) {
    return next(error);
  }
});

const port = process.env.PORT || 13579;
app.listen(port, () => console.log(`Service is listening on port ${port}..`));

However, this results in an error (I doubt the error message is relevant, but sharing it nonetheless):

Error: No wallet address found
    at Object.validateAndFormatWalletAddress (/root/opensea/opensea-creatures/node_modules/opensea-js/src/utils/utils.ts:928:11)
    at OpenSeaPort.<anonymous> (/root/opensea/opensea-creatures/node_modules/opensea-js/src/seaport.ts:1994:22)
    at step (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:40:23)
    at Object.next (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:21:53)
    at /root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:15:71
    at new Promise (<anonymous>)
    at __awaiter (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:11:12)
    at OpenSeaPort._makeSellOrder (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:2038:16)
    at OpenSeaPort.<anonymous> (/root/opensea/opensea-creatures/node_modules/opensea-js/src/seaport.ts:625:30)
    at step (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:40:23)
    at Object.next (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:21:53)
    at /root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:15:71
    at new Promise (<anonymous>)
    at __awaiter (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:11:12)
    at OpenSeaPort.createSellOrder (/root/opensea/opensea-creatures/node_modules/opensea-js/lib/seaport.js:604:16)
    at /root/opensea/opensea-creatures/scripts/service.js:58:47

The point I am making is, the same functionality that is working in the first listing now breaks down when I transfer it to the POST handler, so I doubt it has anything to do with the OpenSea SDK being broken.

user10931326
  • 787
  • 2
  • 8
  • 15

1 Answers1

1

The error message is very relevant. The error message is saying Error: No wallet address found. This means that whatever parameter handles the wallet address, most likely accountAddress which is set to req.body.ownerAddress, is either null or invalid.

I would double check the values in your request body because they are the likely cause.

tantalum
  • 2,354
  • 1
  • 15
  • 22
  • You likely need some sort of body parser middleware like [body-parser](http://expressjs.com/en/resources/middleware/body-parser.html). I don't see where you've included a reference to a body parser. – kevintechie Jan 25 '22 at 16:13
  • @kevintechie I checked with the caller; it turned out that indeed it was because of a misnamed parameter in the request body. Silly mistake on both of us, really. I should delete this question because it isn't useful at all. – user10931326 Jan 25 '22 at 16:15
  • Bummer. Glad you figured it out. It's also good that you followed up here with a comment as to the reason. – kevintechie Jan 25 '22 at 16:32