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

@kaiachain/ethers-ext

v1.1.0

Published

ethers.js extension for kaia blockchain

Downloads

199

Readme

Ethers.js Extension for Kaia

Ethers.js Extension for Kaia offers:

  • Drop-in replacement to ethers.Wallet that handles both Ethereum and Kaia transaction types involving AccountKey and TxTypes.
  • Drop-in replacement to ethers.providers.JsonRpcProvider that provides accesses to both Ethereum RPCs and Kaia-specific RPCs.
  • Drop-in replacement to ethers.Web3Provider to work with both MetaMask (window.ethereum) and Kaikas (window.klaytn)

Note for ethers v6

@kaiachain/ethers-ext supports both ethers v5 and v6. However, you need to use the right packages which are specified for each ethers version. So ethers v5 must be used with packages from @kaiachain/ethers-ext/v5 and ethers v6 is only compatible with @kaiachain/ethers-ext/v6.

NOTE: If the import path has no version sub-path (@kaiachain/ethers-ext), ethers v5 will be used by default.

  • Don't: Mixing ethers v6 and ethers-ext for ethers v5

    const ethers = require("ethers"); // ethers v6
    const { Wallet } = require("@kaiachain/ethers-ext/v5");
    
    const provider = new ethers.JsonRpcProvider(
      "https://public-en-kairos.node.kaia.io"
    );
    const wallet = new Wallet("<private key>", provider);
  • Do: Using with ethers v5

    const ethers = require("ethers"); // ethers v5
    const { Wallet } = require("@kaiachain/ethers-ext/v5");
    
    const provider = new ethers.providers.JsonRpcProvider(
      "https://public-en-kairos.node.kaia.io"
    );
    const wallet = new Wallet("<private key>", provider);
  • Do: Using with ethers v6

    const ethers = require("ethers"); // ethers v6
    const { Wallet } = require("@kaiachain/ethers-ext/v6");
    
    const provider = new ethers.JsonRpcProvider(
      "https://public-en-kairos.node.kaia.io"
    );
    const wallet = new Wallet("<private key>", provider);
  • Do: Using ethers-ext only

    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext/v5");
    // or
    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext/v6");
    
    const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
    const wallet = new Wallet("<private key>", provider);

Install

Node.js

  • Install

    npm install --save @kaiachain/ethers-ext ethers@5 # or ethers@6
  • ESM or TypeScript

    import { Wallet, JsonRpcProvider } from "@kaiachain/ethers-ext";
    
    // esm
    // v5
    import { v5 } from "@kaiachain/ethers-ext";
    const { Wallet, JsonRpcProvider } = v5;
    // v6 
    import { v6 } from "@kaiachain/ethers-ext";
    const { Wallet, JsonRpcProvider } = v6;
    
    // esm subpath import. If using typescript, add "moduleResolution": "nodenext" to tsconfig.json
    // v5
    import { Wallet, JsonRpcProvider } from "@kaiachain/ethers-ext/v5";
    // v6
    import { Wallet, JsonRpcProvider } from "@kaiachain/ethers-ext/v6";
    
    const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
    const wallet = new Wallet("<private key>", provider);
  • CommonJS

    // v5
    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext");
    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext").v5;
    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext/v5");
    // v6
    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext").v6;
    const { Wallet, JsonRpcProvider } = require("@kaiachain/ethers-ext/v6");
    
    const provider = new JsonRpcProvider("https://public-en-kairos.node.kaia.io");
    const wallet = new Wallet("<private key>", provider);

Browser

It is not recommended to use CDNs in production, But you can use below for quick prototyping. using ethers-ext.buldle.js for ethers v5 and ethers-ext.v6.bundle.js for ethers v6

<script src="https://cdn.jsdelivr.net/npm/@kaiachain/ethers-ext@latest/dist/ethers-ext.bundle.js"></script>
<script>
  const provider = new ethers_ext.providers.Web3Provider(window.klaytn);
</script>

Usage

See example and test.

Class extension design

classDiagram
    namespace ethers_v5 {
        class ethers_Signer["ethers.Signer"] {
            provider
            checkTransaction()
            populateTransaction()
            sendTransaction()
        }
        class ethers_Wallet["ethers.Wallet"] {
            connect()
            getAddress()
            signMessage()
            signTransaction()
            static fromEncryptedJson()
            static fromEncryptedJsonSync()
        }
        class ethers_JsonRpcSigner["ethers.JsonRpcSigner"] {
            connect()
            connectUnchecked()
            getAddress()
            signMessage()
            signTransaction()
            sendUncheckedTransaction()
            _legacySignMessage()
            _signTypedData()
            override sendTransaction()
        }

        class ethers_Provider["ethers.Provider"] {
        }
        class ethers_BaseProvider["ethers.BaseProvider"] {
        }
        class ethers_JsonRpcProvider["ethers.JsonRpcProvider"] {
            getSigner()
            send()
        }
        class ethers_Web3Provider["ethers.Web3Provider"] {
            override send()
        }
        class ethers_ExternalProvider["ethers.ExternalProvider"] {
            isMetaMask
            request()
        }
    }
    namespace klaytn_ethers_ext {
        class Wallet {
            override getAddress()
            override checkTransaction()
            override populateTransaction()
            override signTransaction()
            override sendTransaction()
            override static fromEncryptedJson()
            override static fromEncryptedJsonSync()
            signTransactionAsFeePayer()
            sendTransactionAsFeePayer()
            static fromEncryptedJsonList()
            static fromEncryptedJsonListSync()
        }
        class JsonRpcSigner {
            override connectUnchecked()
            override getAddress()
            override signMessage()
            override checkTransaction()
            override populateTransaction()
            override signTransaction()
            override _legacySignMessage()
            override _signTypedData()
            override sendTransaction()
            override sendUncheckedTransaction()
        }

        class JsonRpcProvider {
            admin
            debug
            governance
            klay
            net
            personal
            txpool

            override getSigner()
            override send()
        }
        class Web3Provider {
            admin
            debug
            governance
            klay
            net
            personal
            txpool

            override getSigner()
        }
        class ExternalProvider {
            isKaikas
        }
    }

    ethers_Signer <|-- ethers_Wallet
    ethers_Signer <|-- ethers_JsonRpcSigner

    ethers_Wallet <|-- Wallet
    ethers_JsonRpcSigner <|-- JsonRpcSigner


    ethers_Provider <|-- ethers_BaseProvider
    ethers_BaseProvider <|-- ethers_JsonRpcProvider
    ethers_JsonRpcProvider <|-- ethers_Web3Provider

    ethers_JsonRpcProvider <|-- JsonRpcProvider
    ethers_Web3Provider <|-- Web3Provider
    ethers_ExternalProvider <|-- ExternalProvider