npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wan-dex-sdk-wallet

v0.2.2

Published

Nearly every dapp needs to connect to a crypto wallet for Wanchain. There are many options such as WanMask, ledger. WanDevs sdk wallet makes it easier to integrate different kinds of wallets together, and give an uniform interfaces to interative with them

Downloads

91

Readme

Introduction

Nearly every dapp needs to connect to a crypto wallet for Wanchain. There are many options such as WanMask, ledger. WanDevs sdk wallet makes it easier to integrate different kinds of wallets together, and give an uniform interfaces to interative with them.

WanDevs sdk wallets also support browser local wallets. Secrets are saved in browser localstorage under your domain.

There is a default ui in this package. You can also implement another ui as you wish.

web-screen-shot

Support wallets:

  • WanMask
  • Browser Local Wallet
  • Ledger Wallet
  • Trezor Wallet
  • web3 inject Wallet
  • Wanchain Light Wallet

Basic Usage Guide

This package requires React and Redux.

Step1: install npm package

npm i wan-dex-sdk-wallet

Step2: Wallet Reducer

The store should know how to handle actions coming from the wallet components. To enable this, we need to pass the WalletReducer to your store.

import { createStore, combineReducers } from "redux";
import { WalletReducer } from "wan-dex-sdk-wallet";

const rootReducer = combineReducers({
  // ...your other reducers here
  // you have to pass WalletReducer under 'WalletReducer' key
  WalletReducer
});

const store = createStore(rootReducer);

Step3: Wallet Component

To make the wallet logic work. We need to mount the Wallet and WalletButton components into your app. They should be mounted into Provider(see more details about Provider in react-redux). When the components is initialized, some monitors will start to work as well. They are monitoring the web3 wallet status(not installed, locking, account changed), ledger status(locked or not), and balances of all available addresses. You can config wallet through props. See more datials in the api section below.

import React from "react";
import { Provider } from "react-redux";
import { Wallet, WalletButton } from "wan-dex-sdk-wallet";
import { store } from "./store";
import "wan-dex-sdk-wallet/index.css";

class App extends React.Component {
  render() {
    return (
      <Provider store={store}>
        // ... your components
        <Wallet nodeUrl="https://ropsten.infura.io" />
        <WalletButton />
      </Provider>
    );
  }
}

Step4: Use Account

We can get the current selected account by using selector functions.

import React from "react";
import { connect } from "react-redux";

class App extends React.Component {
  signMessage = async () => {
    const { currentAccount } = this.props;
    const signature = await currentAccount.wallet.signPersonalMessage("test message");
    console.log(signature);
  };

  render() {
    return (
      <div>
        <button onClick={this.signMessage} />
      </div>
    );
  }
}
export default connect(state => {
  return {
    currentAccount: getSelectedAccount(state)
  };
})(App);

API

Wallet Component Props

| Name | Type | Default | Desc | | ----------------- | ------------ | --------------------------- | ------------------------------------------------------------------------------------------------- | | nodeUrl | String | https://ropsten.infura.io | Ethereum JSON RPC Endpoint. | | defaultWalletType | String | EXTENSION | default selected wallet type. Options are EXTENSION, Wan-Wallet, WALLETCONNECT, Ledger. | | translations | Translations | defaultTranslations | i18n translations. | | walletTypes | Array | defaultWalletTypes | customized wallets. | | menuOptions | Option[] | defaultMenuOptions | customized wallet menu. | | loadWalletActions | Actions | {} | customized load wallet actions. | | customLocalWallet | WalletClass | WanWallet | customized local wallet class. | | hideLocalWallet | Boolean | false | Hide local wallet menu items. | | unit | String | ETH | balance unit | | decimals | number | 18 | balance decimals |

Selectors

Methods to get data from redux store.

  • getAccount(state, accountID) Return the corresponding account
  • getSelectedAccount(state) Return the selected account
  • getAccounts(state) Return all available accounts

Action creators

These functions are redux action creators. You need to dispatch the result to store.

  • selectAccount(accountID, type) Change Selected Account
  • unlockBrowserWalletAccount(accountID, password) Unlock a browser local wallet
  • showWalletModal() Show the wallets modal
  • hideWalletModal() Hide the wallets modal

Account functions

When we get an account from redux store, we can call some functions of account.wallet object.

Send Transaction (eth_sendTransaction)

/**
 *  Draft transaction
 */
const tx = {
  from: "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",
  to: "0x0000000000000000000000000000000000000000",
  nonce: 1,
  gas: 100000,
  value: 0,
  data: "0x0"
};

/**
 *  Send transaction
 */
const txId = await wallet.sendTransaction(tx);

Sign Personal Message (personal_sign)

/**
 *  Draft Message Parameters
 */
const msgParams = [
  "WANCHAIN-AUTHENTICATION" //message
];

/**
 *  Sign personal message
 */
const signature = await wallet.signPersonalMessage(msgParams);

Send Custom Request

/**
 *  Draft Custom Request
 */
const customRequest = [
  "eth_getTransactionReceipt", //method
  ["0x452817c981809fb7fab716dc84114b97c9ad2542c72fb9ed2c64d79e1bddb937"] //params
];

/**
 *  Send Custom Request
 */
const customResponse = await wallet.sendCustomRequest(customRequest);

Try the examples

There are some examples projects. You can find commands to start these examples in package.json and source code in examples dir.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details