このページは英語からの機械翻訳を使用しており、誤りや不明瞭な表現が含まれている可能性があります。最も正確な情報については、オリジナルの英語版をご覧ください。頻繁な更新のため、一部のコンテンツはオリジナルの英語になっている可能性があります。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)