This document describes how to use Chain
to initialize an environment instance.
Introduce the JS SDK.
Use the TLS protocol based on the node environment.
const Chain = require('@alipay/mychain/index.node')
Create a connection instance.
Take the creation of connection instances in the node environment as an example.
const Chain = require("@alipay/mychain/index.node") // Use the TLS protocol in the node environment
const fs = require("fs")
const accountKey = fs.readFileSync("./certs/user.pem", { encoding: "utf8" })
const accountPassword = "123abc" // To be replaced with the user-defined user.pem password
const keyInfo = Chain.utils.getKeyInfo(accountKey, accountPassword)
const passphrase = "123abc" // To be replaced with the user-defined client.key password
//Configuration items
let opt = {
host: '127.0.0.1', //IP of the target blockchain node
port: 18130, //Port number
timeout: 30000, //Time configuration for the connection timeout period
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
}
//Initialize a connection instance
const chain = Chain(opt)