0

below is a controller and service code

import { Body, Controller, Get, Post, HttpStatus, Res } from '@nestjs/common';
import { AppService } from './app.service';
import { request } from '../utils/requestDto';

@Controller('transaction')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }

  @Post()
  async generateQrr(@Body() requestDto: request, @Res() res:any) {
    try {
      const qrCode = await this.appService.generateQr(requestDto);
      res.json(qrCode);
    } catch (error) {
      res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({ message: 'QR code generation failed' });
    }
  }
}




import { Injectable } from '@nestjs/common';
import { request } from '../utils/requestDto';
import EthereumQRPlugin from 'ethereum-qr-code';

@Injectable()
export class AppService {
  getHello(): string {
    return 'Hello World!';
  }

  async generateQr(requestDto: request) {
    const { tokenAddress, to, amount } = requestDto;

    try {
      console.log('before the initialization')
      // Create an instance of EthereumQRPlugin
      const qr = new EthereumQRPlugin();
      console.log('after the initialization');

      // Define the data object for the transfer function of the ERC20 contract
      const data = await qr.createTransactionDataObject(
        {
          "to": tokenAddress,
          "from": "0xsenderaddress",
          "value": 0,
          "gas": 10000000000,
          "chainId": 1,
          "mode": "contract_function",
          "functionSignature": {
            "name": "transfer",
            "payable": false,
            "args": [
              {
                "name": "to",
                "type": "address"
              },
              {
                "name": "value",
                "type": "uint"
              }
            ]
          },
          "argsDefaults": [
            {
              "name": "to",
              "value": to
            },
            {
              "name": "value",
              "value": amount
            }
          ]
        });
      console.log('before the qr code generation');

      // Generate QR code using the provided data object
      const qrCode = await qr.toDataUrl(data);

      return qrCode;
    } catch (error) {
      throw new Error('QR code generation failed');
    }
  }
}




what i figued out is this is the problem with library it doesn't have typings for the library i have created a module now but when ever i try to invoke the constructor of class of library to use it doesn't return anything also tried with the implementing the interface of library in module but it doesn't make any differene

{
    "message": "QR code generation failed"
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.