【问题标题】:Hyperledger Fabric / Nodejs - what's the difference between running a contract with node and fabric-chaincode-nodeHyperledger Fabric / Nodejs - 使用节点和fabric-chaincode-node运行合约有什么区别
【发布时间】:2022-08-05 16:47:19
【问题描述】:

在浏览包含 Node.js 中示例的 fabric-samples 存储库时,我注意到一些链代码使用 fabric-chaincode-node 而其他链代码仅在执行 npm start 命令时使用 node

fabric-chaincode-node 为例:

\"name\": \"fabcar\",
\"version\": \"1.0.0\",
\"description\": \"FabCar contract implemented in JavaScript\",
\"main\": \"index.js\",
\"engines\": {
   \"node\": \">=12\",
   \"npm\": \">=6.9\"
},
\"scripts\": {
   \"lint\": \"eslint .\",
   \"pretest\": \"npm run lint\",
   \"test\": \"nyc mocha --recursive\",
   \"start\": \"fabric-chaincode-node start\"
},
\"engineStrict\": true,
\"author\": \"Hyperledger\",
\"license\": \"Apache-2.0\",
\"dependencies\": {
   \"fabric-contract-api\": \"^2.0.0\",
   \"fabric-shim\": \"^2.0.0\"
}

node 为例:

{
    \"name\": \"abstore\",
    \"version\": \"1.0.0\",
    \"description\": \"ABstore chaincode implemented in node.js\",
    \"engines\": {
        \"node\": \">=8.4.0\",
        \"npm\": \">=5.3.0\"
    },
    \"scripts\": {
        \"start\": \"node abstore.js\"
    },
    \"engine-strict\": true,
    \"license\": \"Apache-2.0\",
    \"dependencies\": {
        \"fabric-shim\": \"^2.0.0\"
    }
}

我想知道使用 fabric-chaincode-node 和 node 运行 npm start 命令有什么区别。取决于 Hyperledger Fabric 版本?这取决于我正在使用什么包,即fabric-shim 只需要节点,而fabric-contract-api 需要fabric-chaincode-node 才能正确运行?

    标签: node.js hyperledger-fabric hyperledger hyperledger-chaincode


    【解决方案1】:

    node abstore.js 开头的链码示例将是使用较低级别的较旧示例织物垫片API 直接实现智能合约。正在运行的代码将包含类似于shim.start(new Chaincode()); 的行,用于以编程方式启动链代码。

    fabric-chaincode-node start 开头的链码示例是使用更新的示例面料合同API用于实现智能合约的 API。该 API 基于并扩展了织物垫片API,并且是推荐的方法。

    此处有关于如何使用当前 API 的更详细说明:

    https://github.com/hyperledger/fabric-chaincode-node/blob/main/TUTORIAL.md

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多