icon-sdk-js icon indicating copy to clipboard operation
icon-sdk-js copied to clipboard

Example Issue

Open sangbeomji89 opened this issue 2 years ago • 3 comments

Hi~ I tried to use examples about 'icon-sdk-js' .

I Just did Copy & Paste

const httpProvider = new HttpProvider('https://ctz.solidwallet.io/api/v3');
const iconService = new IconService(httpProvider);

above code.

And run the code with nodejs. But I occur "ERROR" about HttpProvider is not defined.

const httpProvider = new HttpProvider('https://ctz.solidwallet.io/api/v3');
                     ^

ReferenceError: HttpProvider is not defined

I cannot tried any more.

Plz check there issue.

sangbeomji89 avatar Oct 16 '22 12:10 sangbeomji89

Could you try this?

import IconService from 'icon-sdk-js';
const { HttpProvider } = IconService;
const httpProvider = new HttpProvider("https://ctz.solidwallet.io/api/v3");
const iconService = new IconService(httpProvider);

inwonkim avatar Oct 18 '22 23:10 inwonkim

also other kind of error

/~/test-icx.js:3 const httpProvider = new HttpProvider("https://ctz.solidwallet.io/api/v3"); ^

TypeError: HttpProvider is not a constructor at Object. (/~/test-icx.js:3:22) at Module._compile (node:internal/modules/cjs/loader:1103:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47

sangbeomji89 avatar Oct 20 '22 05:10 sangbeomji89

Have you tried the following ?

import IconService from 'icon-sdk-js';

const httpProvider = new IconService.HttpProvider('https://ctz.solidwallet.io/api/v3');
const iconService = new IconService(httpProvider);

related issue : https://github.com/icon-project/icon-sdk-js/issues/43

ICONationDevTeam avatar Oct 20 '22 12:10 ICONationDevTeam

Has anyone face this issue: I am using es6 and tried with both node v18 and v16 didn't work....anybody has any solution?

viveksharmapoudel avatar Mar 17 '23 09:03 viveksharmapoudel

@viveksharmapoudel , @sangbeomji89 From version 1.4.0, modules such as HttpProver are exported at the top level of the library. Try latest version.

inwonkim avatar May 03 '23 05:05 inwonkim