ethers/lib/utils#isBytesLike TypeScript Examples

The following examples show how to use ethers/lib/utils#isBytesLike. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From ccip-read with MIT License 6 votes vote down vote up
async handleRequest(req: express.Request, res: express.Response) {
    let sender: string;
    let callData: string;

    if (req.method === 'GET') {
      sender = req.params.sender;
      callData = req.params.callData;
    } else {
      sender = req.body.sender;
      callData = req.body.data;
    }

    if (!isAddress(sender) || !isBytesLike(callData)) {
      res.status(400).json({
        message: 'Invalid request format',
      });
      return;
    }

    try {
      const response = await this.call({ to: sender, data: callData });
      res.status(response.status).json(response.body);
    } catch (e) {
      res.status(500).json({
        message: `Internal server error: ${(e as any).toString()}`,
      });
    }
  }