All Products
Search
Document Center

Blockchain as a Service:Environment Interface

Last Updated:May 22, 2019

This document describes how to use Chain to initialize an environment instance.

  1. Introduce the JS SDK.

    Use the TLS protocol based on the node environment.

    1. const Chain = require('@alipay/mychain/index.node')
  2. Create a connection instance.

    Take the creation of connection instances in the node environment as an example.

    1. const Chain = require("@alipay/mychain/index.node") // Use the TLS protocol in the node environment
    2. const fs = require("fs")
    3. const accountKey = fs.readFileSync("./certs/user.pem", { encoding: "utf8" })
    4. const accountPassword = "123abc" // To be replaced with the user-defined user.pem password
    5. const keyInfo = Chain.utils.getKeyInfo(accountKey, accountPassword)
    6. const passphrase = "123abc" // To be replaced with the user-defined client.key password
    7. //Configuration items
    8. let opt = {
    9. host: '127.0.0.1', //IP of the target blockchain node
    10. port: 18130, //Port number
    11. timeout: 30000, //Time configuration for the connection timeout period
    12. cert: fs.readFileSync("./certs/client.crt", { encoding: "utf8" }),
    13. ca: fs.readFileSync("./certs/ca.crt", { encoding: "utf8" }),
    14. key: fs.readFileSync("./certs/client.key", { encoding: "utf8" }),
    15. userPublicKey: keyInfo.publicKey,
    16. userPrivateKey: keyInfo.privateKey,
    17. userRecoverPublicKey: keyInfo.publicKey,
    18. userRecoverPrivateKey: keyInfo.privateKey,
    19. passphrase: passphrase
    20. }
    21. //Initialize a connection instance
    22. const chain = Chain(opt)