Skip to content

Initializing SDK in React Project #74

@tainnhan

Description

@tainnhan

Hi,

I create a new fresh react project and I wanted to initialize the sdk with:

 npx create-react-app test --template typescript 
 npm i @loopring-web/loopring-sdk --save

I used node version v18.18.1

I used the following code into my app.tsx.

import { UserAPI, ExchangeAPI, AmmpoolAPI, DelegateAPI, GlobalAPI, NFTAPI, WalletAPI, WsAPI, ChainId } from '@loopring-web/loopring-sdk';
export class LoopringAPIClass {
  public static userAPI: UserAPI;
  public static exchangeAPI: ExchangeAPI;
  public static ammpoolAPI: AmmpoolAPI;
  public static walletAPI: WalletAPI;
  public static wsAPI: WsAPI;
  public static nftAPI: NFTAPI;
  public static delegate: DelegateAPI;
  public static globalAPI: GlobalAPI;
  //public static contractAPI: typeof ContractAPI; #btw I didn't found any import so I commented it
  public static __chainId__: ChainId;
  public static InitApi = (chainId: ChainId) => {
    LoopringAPIClass.userAPI = new UserAPI({ chainId });
    LoopringAPIClass.exchangeAPI = new ExchangeAPI({ chainId });
    LoopringAPIClass.globalAPI = new GlobalAPI({ chainId });
    LoopringAPIClass.ammpoolAPI = new AmmpoolAPI({ chainId });
    LoopringAPIClass.walletAPI = new WalletAPI({ chainId });
    LoopringAPIClass.wsAPI = new WsAPI({ chainId });
    LoopringAPIClass.nftAPI = new NFTAPI({ chainId });
    LoopringAPIClass.delegate = new DelegateAPI({ chainId });
    LoopringAPIClass.__chainId__ = chainId;
    //LoopringAPI.contractAPI = ContractAPI; #btw I didn't found any import so I commented it
  };
}
/* env:
 * test:  sdk.ChainId.GOERLI 
 * eth:  sdk.ChainId.MAINNET 
 */
LoopringAPIClass.InitApi(5); 

When running

npm run build

I get many errors that looks like this:

Module not found: Error: Can't resolve 'assert' in '/Users/******/Desktop/hello/node_modules/ethereumjs-util/dist'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }'
        - install 'assert'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "assert": false }

Can someone help me ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions