本文へスキップ
このページは英語からの機械翻訳を使用しており、誤りや不明瞭な表現が含まれている可能性があります。最も正確な情報については、オリジナルの英語版をご覧ください。頻繁な更新のため、一部のコンテンツはオリジナルの英語になっている可能性があります。Crowdinでの取り組みに参加して、このページの翻訳改善にご協力ください。 (Crowdin translation page, Contributing guide)

kaia用のWeb3.jsエクステンション

Web3.js Extension for kaia offers:

  • Drop-in replacement to new Web3(...) that supports both Ethereum and kaia transaction types involving AccountKey and TxTypes. 詳しくはWeb3オブジェクトの修正の項を参照。

インストール

Node.js

  • インストール

    npm install --save @kaiachain/web3js-ext

  • ESMまたはTypeScript

    import { Web3 } from "@kaiachain/web3js-ext";
    const web3 = new Web3("https://public-en-kairos.node.kaia.io");

  • コモンJS

    const { Web3 } = require("@kaiachain/web3js-ext");
    const web3 = new Web3("https://public-en-kairos.node.kaia.io");

ブラウザ

本番環境でCDNを使用することは推奨されませんが、迅速なプロトタイピングのために以下を使用することができます。


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

アカウント

  • 以下の関数は kaia TxTypes を扱うことができる。 src/account/index.ts を参照。

    // アカウントに依存しない関数
    web3.eth.accounts.recoverTransaction(rlp)
    web3.eth.accounts.signTransaction(obj or rlp)
    web3.eth.accounts.signTransactionAsFeePayer(obj or rlp)
    // アカウントに依存する関数
    var account = web3.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)

  • 以下の関数は、KIP-3 kaia keystore format v4 を扱うことができます。

    web3.eth.accounts.decrypt(keystore)
    web3.eth.accounts.decryptList(keystore)

Eth RPCラッパー

  • 以下の関数は異なるRPCを呼び出し、カイアTxTypesを処理する。 src/eth/index.ts を参照。

    // try klay_protocolVersion, falls back to eth_protocolVersion
    web3.eth.getProtocolVersion()
    // klay_sendTransaction if kaia TxType, otherwise eth_sendTransaction
    // Kaia Wallet互換性のための追加処理
    web3.eth.sendTransaction(obj)
    // klay_sendRawTransaction if kaia TxType, otherwise eth_sendRawTransaction
    web3.eth.sendSignedTransaction(rlp)
    // klay_signTransaction if kaia TxType, otherwise eth_signTransaction
    // Kaia Wallet互換のための追加処理
    web3.eth.signTransaction(obj)

カイアRPC

  • 以下の関数はkaia RPCを呼び出します。 src/web3.ts を参照。

    web3.klay.blockNumber() // klay_blockNumber
    web3.net.networkID() // net_networkID

ページを改善してください。