Socket
Socket
Sign inDemoInstall

@klaytn/web3js-ext

Package Overview
Dependencies
198
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @klaytn/web3js-ext

web3.js extension for Klaytn blockchain


Version published
Weekly downloads
2
decreased by-50%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

Web3.js Extension for Klaytn

Web3.js Extension for Klaytn offers:

  • Drop-in replacement to new Web3(...) that supports both Ethereum and Klaytn transaction types involving AccountKey and TxTypes. See Modifications to the Web3 object section for details

Install

Node.js

  • Install
    npm install --save @klaytn/web3js-ext
    
  • ESM or TypeScript
    import { Web3 } from "@klaytn/web3js-ext";
    const web3 = new Web3("https://public-en-baobab.klaytn.net");
    
  • CommonJS
    const { Web3 } = require("@klaytn/web3js-ext");
    const web3 = new Web3("https://public-en-baobab.klaytn.net");
    

Browser

It is not recommended to use CDNs in production, But you can use below for quick prototyping.

<script src="https://cdn.jsdelivr.net/npm/@klaytn/web3js-ext@latest/dist/web3js-ext.bundle.js"></script>
<script>
const web3 = new web3_ext.Web3(window.klaytn);
</script>

Usage

See example and test.

Modifications to the Web3 object

See DESIGN for source code organization.

Accounts

  • Following functions can handle Klaytn TxTypes. See src/account/index.ts
    // account independent functions
    web3.eth.accounts.recoverTransaction(rlp)
    web3.eth.accounts.signTransaction(obj or rlp)
    web3.eth.accounts.signTransactionAsFeePayer(obj or rlp)
    
    // account-bound functions
    var account = web3.eth.accounts.create()
    var account = web3.eth.accounts.privateKeyToAccount(priv)
    var account = web3.eth.accounts.decrypt(keystore)
    account.signTransaction(obj or rlp)
    account.signTransactionAsFeePayer(obj or rlp)
    
  • Following functions can handle the KIP-3 Klaytn keystore format v4
    web3.eth.accounts.decrypt(keystore)
    web3.eth.accounts.decryptList(keystore)
    

Eth RPC wrappers

  • Following functions calls different RPC, and handle Klaytn TxTypes. See src/eth/index.ts
    // Try klay_protocolVersion, falls back to eth_protocolVersion
    web3.eth.getProtocolVersion()
    
    // klay_sendTransaction if Klaytn TxType, otherwise eth_sendTransaction
    // Additional treatment for Kaikas compatibility
    web3.eth.sendTransaction(obj)
    
    // klay_sendRawTransaction if Klaytn TxType, otherwise eth_sendRawTransaction
    web3.eth.sendSignedTransaction(rlp)
    
    // klay_signTransaction if Klaytn TxType, otherwise eth_signTransaction
    // Additional treatment for Kaikas compatibility
    web3.eth.signTransaction(obj)
    

Klaytn RPCs

  • Following functions calls Klaytn RPCs. See src/web3.ts
    web3.klay.blockNumber() // klay_blockNumber
    web3.net.networkID() // net_networkID
    

Keywords

FAQs

Last updated on 28 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc