0

I create a Theta Token wallet, get its balance with theta.js (@thetalabs/theta-js) in Node Js app. But when I try to get a transaction, I get error: fetch is undefined. I thing, theta.js uses fetch. How can I use theta js in Node.js apps? I tried add node-fetch lib, but it doesn't help me.

Maybe, there is another lib for Node apps with theta?

Mo J
  • 93
  • 7

2 Answers2

0

You can use import fetch from 'node-fetch'; globalThis.fetch = fetch; Since you need a global scope to use fetch here.

Gunesh Shanbhag
  • 559
  • 5
  • 13
0

It works for me....install isomorphic-fetch using the command:

npm i isomorphic-fetch

and then require it in your file using:

const fetch = require('isomorphic-fetch')

It will work..check this out.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31