snapshot-labs / snapshot.js

A TypeScript SDK for Snapshot
https://docs.snapshot.org/snapshot.js
MIT License
229 stars 577 forks source link

Getting an error Cannot read properties of undefined (reading 'utils') while execution snapshot.utils.getVp() or any other method #1030

Closed HamzaBhatti125 closed 2 months ago

HamzaBhatti125 commented 2 months ago

Expected behavior

According to the doc, the below mentioned method should return me some response. snapshot.utils.getVp(address, network, strategies, snapshot, space, delegation, options).then(vp => { console.log('Voting Power', vp); });

Actual behavior

But I am getting an error TypeError: Cannot read properties of undefined (reading 'utils'). I have installed the package by using npm i @snapshot-labs/snapshot.js. I am using it in nestJs project

Steps to reproduce the behavior

Just install the package and write the service code which is mentioned the snapshot.js doc

image image

ChaituVR commented 2 months ago

Hi @HamzaBhatti125 How do you import snapshot.js?

HamzaBhatti125 commented 2 months ago

@ChaituVR I am importing in the same way as mentioned in the doc i.e.

import snapshot from '@snapshot-labs/snapshot.js';

I've also tried import {snapshot} from '@snapshot-labs/snapshot.js'; import {utils} from '@snapshot-labs/snapshot.js';

but it is giving me error while compiling image

ChaituVR commented 2 months ago

Not an expert in nest.js but

It works like this

import * as snapshot from '@snapshot-labs/snapshot.js';

snapshot['utils'].getVp(....)
ChaituVR commented 2 months ago

Here is an example https://stackblitz.com/edit/nestjs-typescript-starter-elhxtv?file=src%2Fapp.service.ts

HamzaBhatti125 commented 2 months ago

@ChaituVR It worked! thank you