Giter Club home page Giter Club logo

everscale-standalone-client's Introduction

Logo

Everscale standalone client   Latest Version Docs badge

About

Standalone client to the Everscale blockchain to use with everscale-inpage-provider.

Usage

Install

npm install --save everscale-inpage-provider everscale-standalone-client

Example

import { Address, ProviderRpcClient, TvmException } from 'everscale-inpage-provider';

// For browser environment:
import { EverscaleStandaloneClient } from 'everscale-standalone-client';
// Or for nodejs environment:
// import { EverscaleStandaloneClient } from 'everscale-standalone-client/nodejs';

const ever = new ProviderRpcClient({
  fallback: () =>
    EverscaleStandaloneClient.create({
      connection: {
        id: 2, // network id
        type: 'graphql',
        data: {
          // create your own project at https://dashboard.evercloud.dev
          endpoints: ['https://devnet-sandbox.evercloud.dev/graphql'],
        },
      },
    }),
});

async function myApp() {
  await ever.ensureInitialized();

  await ever.requestPermissions({
    permissions: ['basic'],
  });

  const dePoolAddress = new Address('0:2e0ea1716eb93db16077d30e51d092b075ce7f0eb1c08ca5bea67ef48a79368e');

  const dePool = new ever.Contract(DePoolAbi, dePoolAddress);

  try {
    const output = await dePool.methods.getDePoolInfo({}).call();
    console.log(output);
  } catch (e) {
    if (e instanceof TvmException) {
      console.error(e.code);
    }
  }
}

const DePoolAbi = {
  'ABI version': 2,
  header: ['time', 'expire'],
  functions: [
    {
      name: 'getDePoolInfo',
      inputs: [],
      outputs: [
        { name: 'poolClosed', type: 'bool' },
        { name: 'minStake', type: 'uint64' },
        { name: 'validatorAssurance', type: 'uint64' },
        { name: 'participantRewardFraction', type: 'uint8' },
        { name: 'validatorRewardFraction', type: 'uint8' },
        { name: 'balanceThreshold', type: 'uint64' },
        { name: 'validatorWallet', type: 'address' },
        { name: 'proxies', type: 'address[]' },
        { name: 'stakeFee', type: 'uint64' },
        { name: 'retOrReinvFee', type: 'uint64' },
        { name: 'proxyFee', type: 'uint64' },
      ],
    },
  ],
  data: [],
  events: [],
} as const; // NOTE: `as const` is very important here

myApp().catch(console.error);

Build with Vite

Using Vite you will stuck with issue. As workaround you may initialize provider like in the example below.

import { Address, ProviderRpcClient } from 'everscale-inpage-provider';
import { EverscaleStandaloneClient } from 'everscale-standalone-client';

const client = new ProviderRpcClient({
  forceUseFallback: true,
  fallback: () =>
    EverscaleStandaloneClient.create({
      connection: {
        /*...*/
      },
      initInput: '../../node_modules/nekoton-wasm/nekoton_wasm_bg.wasm',
    }),
});

Contributing

We welcome contributions to the project! If you notice any issues or errors, feel free to open an issue or submit a pull request.

License

Licensed under GPL-3.0 license (LICENSE or https://opensource.org/license/gpl-3-0/).

everscale-standalone-client's People

Contributors

30mb1 avatar egorguscha avatar mrwad3r avatar rexagon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

everscale-standalone-client's Issues

Everscale-Standalone-Client Fails with Vite in Production

I am having an issue with the everscale-standalone-client when bundling for production using Vite. The application works fine in the development environment (localhost) but fails when deployed in production.

This is how I am initiating the client:

const Provider = new ProviderRpcClient({
      forceUseFallback: true,
      fallback: () =>
        EverscaleStandaloneClient.create({
          connection: {
            id: 1002, // network id
            group: "dev",
            type: 'jrpc',
            data: {
              endpoint: "https://jrpc-devnet.venom.foundation/rpc",
            },
          },
          initInput: '../../node_modules/nekoton-wasm/nekoton_wasm_bg.wasm',
        }),
    });

The error that I get is:
Screenshot 2023-06-11 at 11 52 02 PM

Upon closer inspection of the source, I found that the function the y in await y(l.initInput); is invoked after
await ensureNekotonLoaded(params.initInput); is called in create()

Screenshot 2023-06-11 at 11 55 01 PM

ensureNekotonLoaded is defined as

core_1.default.ensureNekotonLoaded = (initInput) => {
    if (!clientInitializationStarted) {
        clientInitializationStarted = true;
        (0, nekoton_wasm_1.default)(initInput).then(notifyClientInitialized.resolve).catch(notifyClientInitialized.reject);
    }
    return initializationPromise;
};

So essentially the exact function corresponding to y should be nekoton_wasm_1.default which is nothing but the default import from nekoton-wasm .

I have identified the issue as to why it is undefined, in the source file index.ts the import from nekoton is defined as follows:

import init, * as nt from 'nekoton-wasm';

However, the default export inside nekoton-wasm.js is not init but __wbg_init:

Screenshot 2023-06-12 at 12 05 38 AM

My guess is, this is the reason why the final build is unable to find the method and initialise it.

However, I am not sure why this works perfectly on locally.

Link to GitHub repo which works perfectly locally. (Need to do npm install in the root folder as well as inside src/sdk and src/touch-id-app, then run npm run dev in touch-id-app to start the application)

Package Fails with NextJS in Production

The application works fine in the development environment (localhost) but fails when deployed in production.

this is the error

image

it seems that is related to nekoton_wasm package, for some reason the wasm file couldn´t be loaded into the built files

Please fix conflict of types

Code:

const ever = new ProviderRpcClient({ 
      fallback: () => 
        EverscaleStandaloneClient.create({
          connection: 'mainnet',
        }),
    });

Error:

(property) fallback?: (() => Promise<Provider>) | undefined
Provider factory which will be called if injected provider was not found. Can be used for initialization of the standalone Everscale client
Type '() => Promise<EverscaleStandaloneClient>' is not assignable to type '() => Promise<Provider>'.
  Type 'Promise<EverscaleStandaloneClient>' is not assignable to type 'Promise<Provider>'.
    Type 'EverscaleStandaloneClient' is missing the following properties from type 'Provider': addListener, removeListener, on, once, and 2 more.ts(2322)

expireAt rounding

With locklift 2.4.6 using

  • everscale-inpage-provider 0.3.45
  • everscale-standalone-client 2.1.5
     Error: Expected integer value: 1672031328.4
      at module.exports.__wbg_new_8d2af00bc1e329ee (node_modules/nekoton-wasm/nekoton_wasm_main.js:1830:17)
      at null.<anonymous> (wasm://wasm/004fc35e:1:900709)
      at null.<anonymous> (wasm://wasm/004fc35e:1:630868)
      at Object.module.exports.packIntoCell (node_modules/nekoton-wasm/nekoton_wasm_main.js:445:14)
      at AccountsStorageContext.packIntoCell (node_modules/everscale-standalone-client/client/AccountsStorage/index.js:56:29)
      at WalletV3Account.prepareMessage (node_modules/everscale-standalone-client/client/AccountsStorage/WalletV3.js:61:37)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at sendMessage (node_modules/everscale-standalone-client/client/index.js:737:31)
      at ContractMethodImpl.send (node_modules/everscale-inpage-provider/dist/contract.js:299:33)

the code i hit looks like and occurs in several places

timeout *= properties.message.timeoutGrowFactor

so timeout changes as 60, 72, 86.39999999999999, 103.67999999999999, 124.41599999999998, 60

issue after installing the package

Hello, I'm integrating venom wallet to an already existing website, I am using this repo as a guide https://github.com/web3sp/inpage-provider-playground/blob/master/src/App.tsx

when I installed this package this error came out

image

environment
node: 16.x
package manager: yarn
everscale-standalone-client version: 2.1.18

help would be so much appreciated, thanks!

the code is the following

import React from "react";

import { VenomConnect } from "venom-connect";
import { ProviderRpcClient } from "everscale-inpage-provider";
import {
  ConnectionProperties,
  EverscaleStandaloneClient,
} from "everscale-standalone-client";

const getNetworkData = (checkNetworkId, field) => {
  switch (checkNetworkId) {
    case 1000:
      return NETWORKS.venomTestnet[field];

    case 1:
    default:
      return NETWORKS.venom[field];
  }
};

const NETWORKS = {
  venom: {
    name: "Venom Mainnet",
    checkNetworkId: 1,
    connection: {
      id: 1,
      group: "venom_mainnet",
      type: "jrpc",
      data: {
        endpoint: "https://jrpc.venom.foundation/rpc",
      },
    },
  },
  venomTestnet: {
    name: "Venom Testnet",
    checkNetworkId: 1000,
    connection: {
      id: 1000,
      group: "venom_testnet",
      type: "jrpc",
      data: {
        endpoint: "https://jrpc-testnet.venom.foundation/rpc",
      },
    },
  },
};

const standaloneFallback = (checkNetworkId = 1000) =>
  EverscaleStandaloneClient.create({
    connection: getNetworkData(checkNetworkId, "connection"),
  });

const initVenomConnect = async (checkNetworkId = 1000) => {
  return new VenomConnect({
    theme: "light",
    checkNetworkId: checkNetworkId,
    providersOptions: {
      venomwallet: {
        walletWaysToConnect: [
          {
            // NPM package
            package: ProviderRpcClient,
            packageOptions: {
              fallback:
                VenomConnect.getPromise("venomwallet", "extension") ||
                (() => Promise.reject()),
              forceUseFallback: true,
            },
            packageOptionsStandalone: {
              fallback: standaloneFallback,
              forceUseFallback: true,
            },
            id: "extension",
            type: "extension",
          },
        ],
        defaultWalletWaysToConnect: ["mobile", "ios", "android"],
      },
    },
  });
};

function TestComponent() {
  const OnInitBtnClick = async () => {
    const venomConnect = await initVenomConnect();
  };

  return (
    <section>
      <button onClick={OnInitBtnClick}>Connect venom</button>
    </section>
  );
}

export default TestComponent;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.