0.4.4 • Published 5 months ago

eft-web3 v0.4.4

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

web3 tools

 

install

npm install eft-web3

# or

yarn add eft-web3

 

use

import eft_web3 from 'eft-web3';
const {Web3 , Vote } = eft_web3;
Export Modulequick Link
Web3Jump
VoteJump
BignumberJump
utilsJump

 

web3

    // init
    import {Web3} from "eft-web3";
    const web3 = Web3.init({
        chainId:1,
        // web3stateReactive:reactive,
    });
    

    // state
    web3.state => {
        account: string;
        network: Record<string, any>;
        walletConnectType: string | null;
        provider: Web3Provider;
    }
    

    // function 
    const {
        getAccount,
        getNetwork,
        getProvider,
        getIsLoggedIn,
        getIsinited
    } = web3;
    // asyc function 
    await web3.login('injected' | 'walletconnect' | 'walletlink');
    await web3.logout();


    // web hooks
    function hookFn(){// do something}
    web.on('login' | 'init' | 'logout' | 'networkChanged' | 'accountChanged' | 'chainChanged',hookFn)
    web.off('login' | 'init' | 'logout' | 'networkChanged' | 'accountChanged' | 'chainChanged',hookFn)

 

Vote

TODO

 

BigNumber

BigNumber is a shortcut to the "@ethersproject/bignumber" file and does not rework the original library

 

Utils

import {Utils} from "eft-web3";
const address = `0x1234567890123456789012345678901234567890`;

/**
 * @name shorten
 * @param {string} address
 * @param {key} number | 'symbol' | 'name' | 'choice' | undefinded
 */

// if key is undefinded , return Utils.shortenAddress(address) 
Utils.shorten(address) // 0x1234...7890 

// if key === number limit = key;
// if key === 'symbol' limit = 6;
// if key === 'name' limit = 64;
// if key === 'choice' limit = 12;
// return address.slice(0...limit)
Utils.shorten(address,5) // 0x123...
Utils.shorten(address,'symbol') // 0x1234...