このドキュメントでは、Chain を使用して環境インスタンスを初期化する方法について説明します。
JS SDK を導入します。
ノード環境に基づいて TLS プロトコルを使用します。
const Chain = require('@alipay/mychain/index.node')接続インスタンスを作成します。
ノード環境での接続インスタンスの作成を例に説明します。
const Chain = require("@alipay/mychain/index.node") // ノード環境で TLS プロトコルを使用します const fs = require("fs") const accountKey = fs.readFileSync("./certs/user.pem", { encoding: "utf8" }) const accountPassword = "123abc" // ユーザー定義の user.pem パスワードに置き換えてください const keyInfo = Chain.utils.getKeyInfo(accountKey, accountPassword) const passphrase = "123abc" // ユーザー定義の client.key パスワードに置き換えてください // 構成項目 let opt = { host: '127.0.0.1', // ターゲットブロックチェーンノードの IP port: 18130, // ポート番号 timeout: 30000, // 接続タイムアウト期間の時間構成 cert: fs.readFileSync("./certs/client.crt", { encoding: "utf8" }), ca: fs.readFileSync("./certs/ca.crt", { encoding: "utf8" }), key: fs.readFileSync("./certs/client.key", { encoding: "utf8" }), userPublicKey: keyInfo.publicKey, userPrivateKey: keyInfo.privateKey, userRecoverPublicKey: keyInfo.publicKey, userRecoverPrivateKey: keyInfo.privateKey, passphrase: passphrase } // 接続インスタンスを初期化します const chain = Chain(opt)