标签: blockchain

如何使用 web3 在服务器端对消息进行签名

我正在使用 Node.js 构建一个去中心化应用程序。我需要 node.js 应用程序从前端接收消息,使用 web3.js 签署消息并将签名发送回前端。

我正在考虑将预定义的私钥作为环境变量传递给 node.js 应用程序。然后使用私钥实例化Web3并调用web3.personal.sign对消息进行签名。我需要在服务器端进行签名过程,所以我不认为使用像 Metamask 这样的客户端钱包是适用的。

我是区块链和 Web3 开发的新手,所以我不确定我的要求是否可行。

cryptography node.js blockchain ethereum web3js

2
推荐指数
1
解决办法
3796
查看次数

如何修复 Solidity 中的“部署时迁移遇到无效操作码”错误?

“迁移”在部署时遇到无效的操作码。尝试:

  • 验证您的构造函数参数是否满足所有断言条件。
  • 验证构造函数代码不会越界访问数组。
  • 将原因字符串添加到断言语句中。出现这个错误如何解决

我的migration.sol代码

    // SPDX-License-Identifier: UNLICENSED

    //the version of solidity that is compatible

    pragma solidity ^0.8.0;
    contract Migrations {
      address public owner = msg.sender;
      uint public last_completed_migration;

      modifier restricted() {
        require(
          msg.sender == owner,
          "This function is restricted to the contract's owner"
        );
        _;
      }

      function setCompleted(uint completed) public restricted {
        last_completed_migration = completed;
      }
    }
Run Code Online (Sandbox Code Playgroud)

我的松露 config.js 文件

    // SPDX-License-Identifier: UNLICENSED

    //the version of solidity that is compatible

    pragma solidity ^0.8.0;
    contract Migrations {
      address public owner …
Run Code Online (Sandbox Code Playgroud)

javascript blockchain ethereum solidity

2
推荐指数
1
解决办法
1339
查看次数

如何解码(非常大的值)十六进制字符串到十进制?

我试图解码类似于以下格式的十六进制字符串:

0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe
Run Code Online (Sandbox Code Playgroud)

我能够使用在线计算器对其进行解码.应该是正确的解码数字220892037897060743166.

但是,当我尝试使用python使用以下代码对其进行解码时,它会返回错误:

"0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-1cf86ff46cbc> in <module>()
      9 key=keyarr[0]
     10 
---> 11 "0x00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")

/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/hex_codec.py in hex_decode(input, errors)
     40     """
     41     assert errors == 'strict'
---> 42     output = binascii.a2b_hex(input)
     43     return (output, len(input))
     44 

TypeError: Non-hexadecimal digit found
Run Code Online (Sandbox Code Playgroud)

然后我删除了十六进制数字前面的0x并再次尝试:

"00000000000000000000000000000000000000000000000bf97e2a21966df7fe".decode("hex")
Run Code Online (Sandbox Code Playgroud)

然后输出成为:

'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\xf9~*!\x96m\xf7\xfe'
Run Code Online (Sandbox Code Playgroud)

我实际上不明白输出...

如果您想知道这些数字来自何处,它们来自以太坊区块链(ERC20)令牌.

python hex blockchain ethereum

1
推荐指数
1
解决办法
990
查看次数

如何在超级分层结构中获取资产修改历史记录

我正在使用IBM bluemix区块链服务为我的资产共享演示试用一些智能合约逻辑.

无论如何,在超级分层结构网络中查询资产修改的历史记录.

我已经检查了Fabric 0.6和1.0版本的文档,但我只能找到stub.pushState(key,value_json)stub.getState(key)交换分类帐的宽度.
但是使用stub.getState(key),我只能获取密钥的最新条目,但是如何获取和显示为同一个密钥编写的一系列更改/修改.我已使用迭代遍历块{peeraddress}/Block/getBlock/{Block},但我只获得加密的事务有效负载,因为它的安全性已经开启.我没有想到显示相同密钥的资产修改历史.


请建议我这样做的正确方法.

提前致谢

blockchain hyperledger hyperledger-fabric ibm-cloud

1
推荐指数
2
解决办法
1844
查看次数

如何在生产级部署Hyperledger Fabric V1.0网络?

通过遵循Hyperledger-fabric文档并使用fabric-sdk-java客户端,我已经建立了Hyperledger Fabric V1.0网络,我能够从Java应用程序与网络进行通信。现在,在开发设置中一切正常。但是我仍然不清楚其生产水平的实现。寻找以下方面的有价值的建议,以使其投入生产。

  1. 可以将这种设置用于生产吗?那么如何使用此docker-compose设置构建网络?网络的生产托管有哪些可用选项?
  2. 如果可以在生产中进行设置,则应在所有对等系统中运行此docker-compose设置,然后如何配置docker-compose.yaml以定义不同系统中的每个对等/组织?
  3. 我发现Bluemix区块链服务可以替代,但每月收费很高。那么,是否可以通过定义自己的对等方和组织来部署自己的Hyperledger Fabric V1.0网络呢?

p2p blockchain hyperledger hyperledger-fabric ibm-cloud

1
推荐指数
1
解决办法
2136
查看次数

在centOS中使用Hyperledger Composer-rest-server生成REST API时出错

我可以在CentOS linux服务器中使用hyperledger composer部署业务网络,但是在使用composer-rest-server生成REST api时却出现连接错误?

[root@bctlpblockchain03 ~]#composer network ping -c admin@tutorial-network
The connection to the network was successfully tested: tutorial-network
        version: 0.15.2
        participant: org.hyperledger.composer.system.NetworkAdmin#admin

Command succeeded

[root@bctlpblockchain03 ~]# composer-rest-server
? Enter the name of the business network card to use: admin@tutorial-network
? Specify if you want namespaces in the generated REST API: never use namespaces


? Specify if you want to enable authentication for the REST API using Passport:
No
? Specify if you want to enable event publication over WebSockets: …
Run Code Online (Sandbox Code Playgroud)

linux centos blockchain hyperledger hyperledger-composer

1
推荐指数
1
解决办法
1091
查看次数

什么批准和津贴方法在ERC20标准中真正做了什么?

问题是津贴和批准真的在做什么?

这是什么_spender以及它在做什么?

有人能解释一下吗???

contract Token {
    uint256 public totalSupply;
    function balanceOf(address _owner) constant returns (uint256 balance);
    function transfer(address _to, uint256 value) returns (bool success);
    function transferFrom(address _from, address _to, uint256 value) returns (bool success);
    function approve(address _spender, uint256 _value) returns (bool success);
    function allowance(address _owner, address _spender) constant returns (uint256 remaining);
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
Run Code Online (Sandbox Code Playgroud)

blockchain solidity

1
推荐指数
2
解决办法
528
查看次数

以太坊vs Hyperledger Fabric

我目前正在进行一个项目,该项目将以太坊等公共区块链与Hyperledger Fabric等财团区块链进行比较。

我将在两个平台上设计和实施智能合约,以衡量其交易速度和成本。

将对其他内容进行比较,例如隐私,潜在的可伸缩性,治理和共识协议。

希望在Solidity中编写Eth智能合约,在Golang中编写Fabric。我对此的经验极少,因此我只想实现基本的合同合同,在两个平台上执行多个合同并进行比较。

有没有办法对模拟真实事物的智能合约进行虚拟运行?

blockchain ethereum smartcontracts hyperledger-fabric

1
推荐指数
1
解决办法
308
查看次数

在Substrate中,Babe,Aura和Grandpa之间有什么区别

Substrate支持“可插入共识”,因此开发人员可以从几种共识算法中进行选择。它标配有四种算法:

Some of these (eg babe and grandpa) can even be used together in a single node. What are the differences between each consensus algorithm, and which ones can or should be used together?

consensus blockchain parity-io substrate

1
推荐指数
1
解决办法
102
查看次数

无法更新订购者配置中的batchtimeout?

我创建了一个结构网络,它运行良好。我想更新oderer配置,例如batchtimeout在运行中的网络中。我已按照教程在运行时更新通道配置。本教程适用于添加新组织。但是当我更新订购者配置时,我得到了如下错误

错误:状态发生意外:BAD_REQUEST-将配置更新应用于现有通道“ mychannel”时出错:授权更新:错误验证DeltaSet:未满足[Value] / Channel / Orderer / BatchTimeout的策略:隐式策略评估失败-0子-符合政策,但此政策要求满足“管理员”子政策中的1个

我从所有组织管理员(例如org1和org2)中选择了信封.pb文件。请帮助我。

注意:为此,我使用了fabric-samples第一网络。

编辑:我已经用org1和org2签署了pb文件。我还通过导出以下变量与订购者签署了文件

CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin\@example.com/msp/

CORE_PEER_ADDRESS=orderer.example.com:7050

CORE_PEER_LOCALMSPID=OrdererMSP

CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
Run Code Online (Sandbox Code Playgroud)

日志

11-28 09:13:57.207 UTC [policies] Manager -> DEBU cc4 Manager Channel/Orderer looking up path []
2019-11-28 09:13:57.207 UTC [policies] Manager -> DEBU cc5 Manager Channel/Orderer has managers OrdererOrg
2019-11-28 09:13:57.207 UTC [policies] Evaluate -> DEBU cc6 == Evaluating *policies.implicitMetaPolicy Policy /Channel/Orderer/Admins ==
2019-11-28 09:13:57.207 UTC [policies] Evaluate -> DEBU cc7 This is an implicit meta policy, it will trigger other …
Run Code Online (Sandbox Code Playgroud)

blockchain hyperledger hyperledger-fabric hyperledger-chaincode

1
推荐指数
1
解决办法
75
查看次数