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

After installing signClient connection Node.js app is crashing with walletConnect Core error. #5588

Open
Gostai opened this issue Jan 13, 2025 Discussed in #5587 · 1 comment
Assignees

Comments

@Gostai
Copy link

Gostai commented Jan 13, 2025

Discussed in https://github.com/orgs/WalletConnect/discussions/5587

Originally posted by Gostai January 10, 2025

A Minimal Reproducible Example

It is a simple telegram bot with node-telegram-bot-api. I'm using this files:

package.json

{
  "name": "min",
  "version": "1.0.0",
  "scripts": {
    "compile": "npx rimraf dist && tsc",
    "start": "node ./dist/main.js"
  },
  "dependencies": {    
    "dotenv": "^16.0.3",
    "node-telegram-bot-api": "^0.61.0",
    "@walletconnect/sign-client": "^2.17.3",
    "lokijs": "^1.5.12",
    "qrcode": "^1.5.1"
  },
  "devDependencies": {
    "@types/node-telegram-bot-api": "^0.61.4",
    "@types/qrcode": "^1.5.0",
    "rimraf": "^3.0.2",
    "typescript": "^4.9.5"
  }
} 

tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "lib": ["ESNext", "dom"],
    "resolveJsonModule": true,
    "experimentalDecorators": false,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "useUnknownInCatchVariables": false,
    "noUncheckedIndexedAccess": true,
    "emitDecoratorMetadata": false,
    "importHelpers": false,
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "allowJs": true,
    "outDir": "./dist"
  },
  "include": ["src"],
  "exclude": [
    "./tests","node_modules", "lib", "types"]
} 

.env

TELEGRAM_BOT_TOKEN="Token"
ETH_PROJECT_ID="ID"

and /src folder with two files:

first for bot implemetation

bot.ts

import TelegramBot from 'node-telegram-bot-api';
import * as process from 'process';

const token = process.env.TELEGRAM_BOT_TOKEN!;

export const bot = new TelegramBot(token, { polling: true });

and second for signClient usage with Node.js

main.ts

import dotenv from 'dotenv';
dotenv.config();

import { bot } from './bot';
import QRCode from 'qrcode';
import SignClient from '@walletconnect/sign-client';


bot.on('message', async msg => {
  const chatId = msg.chat.id;
  const projectId = process.env.ETH_PROJECT_ID!;

  const signClient = await SignClient.init({
    projectId,    
    metadata: {
      name: 'Example Dapp',
      description: 'Example Dapp',
      url: '#',
      icons: ['https://walletconnect.com/walletconnect-logo.png']
    }
  });

  try {
    const { uri, approval } = await signClient.connect({
      requiredNamespaces: {
        eip155: {
          methods: [
            'eth_sendTransaction',
            'eth_signTransaction',
            'eth_sign',
            'eth_getTransactionReceipt'
          ],
          chains: ['eip155:84532'],
          events: ['chainChanged', 'accountsChanged']
        }
      }
    });

    if (uri) {
      const image = await QRCode.toBuffer(uri);
      const botMessage = await bot.sendPhoto(chatId, image);

      const session = await approval();

      const [account] = session.namespaces.eip155!.accounts;
      if (account === undefined) {
        bot.deleteMessage(chatId, botMessage.message_id);
        console.log("no account in walletConnect session");
        await bot.sendMessage(chatId, `No account in walletConnect session `);
        return;
      }

      console.log("account: ", account);
    }
  } catch (e) {
    console.error(e)
  }
}); 

I use

npm i
npm run compile
npm run start

Everything is compiling and starting well. I send a message to the bot and it is replying me with the QRcode that I am using with Metamask to connect to BASE Sepolia network. Console is logging my Metamask address and even more, if I send some requests with the connection, they all working well, but not for a long time. Even on this MRE Bot crashes after about 2 minutes of working fine
with ./node_modules/@walletconnect/core/dist/index.cjs.js:1

TypeError: i.terminate is not a function
    at Timeout._onTimeout (/home/gorub/Documents/TONProjects/Novikov/MintBot/min/node_modules/@walletconnect/core/dist/index.cjs.js:1:41151)
    at listOnTimeout (node:internal/timers:594:17)
    at process.processTimers (node:internal/timers:529:7)

Here I provide all the console output

> [email protected] start
> node ./dist/main.js

(node:13755) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:13755) [node-telegram-bot-api] DeprecationWarning: Buffers will have their filenames default to "filename" instead of "data". See https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files for more information on how sending files has been improved and on how to disable this deprecation message altogether.
(node:13755) [DEP0044] DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.
account:  eip155:84532:0xcd5acea374cd26ee5ccde225c1446d72036e21a3
/home/../min/node_modules/@walletconnect/core/dist/index.cjs.js:1
"use strict";Object.defineProperty( ... 
                                                                                                                                                                                                                                                                          
TypeError: i.terminate is not a function
    at Timeout._onTimeout (/home/gorub/Documents/TONProjects/Novikov/MintBot/min/node_modules/@walletconnect/core/dist/index.cjs.js:1:41151)
    at listOnTimeout (node:internal/timers:594:17)
    at process.processTimers (node:internal/timers:529:7)

Node.js v22.11.0

The problem is in @walletconnect/core/dist/index.cjs.js in wt/constructor/resetPingTimeout/setTimeout callback()

I am working on Ubuntu, Node.js 22.11.0, not using walletConnectModal.openModal({ uri }) because of using Telegram Bot frontend Opening QRcodes with MetaMask

Expected behavior

Connection must be successfull and must not result the breaking of the all Bot App.

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

2 participants