实际上,我正在学习ethereum上的智能合同编程,我也在使用松露。现在,我在这里编写本教程:https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains
学习如何创建具有仲裁的dapp。但现在我有麻烦了。
我做的每件事都和描述的一样,但当我做的时候:
truffle migrate我在这里看到了这个错误:
$ truffle migrate
⚠️ Important ⚠️
If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.
Starting migrations...
======================
> Network name: 'development'
> Network id: 10
> Block gas limit: 3758096384
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
- Blocks: 0 Seconds: 0
> Blocks: 0 Seconds: 0
> contract address: 0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
> account: 0xed9d02e382b34818e88B88a309c7fe71E65f419d
> balance: 1000000000
> gas used: 245462
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
- Saving migration to chain.
Error: Number can only safely store up to 53 bits
at assert (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\number-to-bn\~\bn.js\lib\bn.js:6:1)
at BN.toNumber (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\number-to-bn\~\bn.js\lib\bn.js:506:1)
at Object.hexToNumber (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-utils\src\utils.js:234:1)
at Method.outputBlockFormatter [as outputFormatter] (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-helpers\src\formatters.js:239:1)
at Method.formatOutput (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-method\src\index.js:163:1)
at sendTxCallback (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-method\src\index.js:473:1)
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:147:1
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:145:1
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:112:1
at XMLHttpRequest.request.onreadystatechange (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
at XMLHttpRequest._setReadyState (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)
at IncomingMessage.<anonymous> (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Truffle v5.0.1 (core: 5.0.1)
Node v8.11.4现在我不知道为什么。
有谁有同样的问题能帮我吗?
这是我的智能合同:
pragma solidity ^0.4.17;
contract SimpleStorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}还有我的块菌-config.js文件:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 22000, // was 8545
network_id: "*", // Match any network id
gasPrice: 0,
gas: 4500000
},
nodefour: {
host: "127.0.0.1",
port: 22003,
network_id: "*", // Match any network id
gasPrice: 0,
gas: 4500000
},
nodeseven: {
host: "127.0.0.1",
port: 22006,
network_id: "*", // Match any network id
gasPrice: 0,
gas: 4500000
}
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.4.25", // Fetch exact version from solc-bin (default: truffle's version)
}
}
}以及迁移文件:
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
// Pass 42 to the contract as the first constructor parameter
deployer.deploy(SimpleStorage, 2, { privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="] })
};发布于 2019-01-18 15:08:19
所以问题是块时间戳是以纳秒为单位的。
@edgraaff编写了一个代理,它将时间戳从纳秒转换为秒。您可以在这里找到代码-> https://github.com/edgraaff/quorum-rpc-proxy
我要做的是克隆代理并将config.js文件更改为:
module.exports = {
rpcUrl: 'http://localhost:22000',
port: 7545
};在truf-config.js文件中,我不得不更改端口。下面是代码:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545, // was 8545
network_id: "*", // Match any network id
gasPrice: 0,
gas: 4500000
},
nodefour: {
host: "127.0.0.1",
port: 22003,
network_id: "*", // Match any network id
gasPrice: 0,
gas: 4500000
},
nodeseven: {
host: "127.0.0.1",
port: 22006,
network_id: "*", // Match any network id
gasPrice: 0,
gas: 4500000
}
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.4.25", // Fetch exact version from solc-bin (default: truffle's version)
}
}
}感谢@edgraaff
发布于 2019-02-08 15:08:44
代理是不够的,因为web3.js可以通过ws获得订阅块
在仲裁中,按数字获取块也被打破,它只接受十六进制,但是web3.js假设十六进制是块散列
这是我的解决办法
web3.extend({
property: 'eth',
methods: [new web3.extend.Method({
name: 'getBlockByNumber',
call: 'eth_getBlockByNumber',
params: 2,
inputFormatter: [web3.extend.formatters.inputBlockNumberFormatter, v => !!v],
outputFormatter: web3.extend.formatters.outputBlockFormatter
})]
});
web3.utils.hexToNumber = v => {
if (!v) return v;
try {
return numberToBN(v).toNumber();
} catch (e) {
return numberToBN(v).toString();
}
};现在要小心时间戳是字符串
以下是web3.js回购https://github.com/ethereum/web3.js/issues/1215中的相关问题
发布于 2020-05-19 07:28:35
现在(2020年5月),基本上有两种方法可以解决这个问题:
type: "quorum"添加到truffle-config.js或networks.js中,如: myLocalQuorum: {
protocol: 'http',
host: 'localhost',
port: 22000,
gas: 5000000,
gasPrice: 0,
networkId: '*',
type: "quorum"
},@truffle/hd-wallet-provider,没有简单的解决办法,但是您可以将您的共识转换为istanbul而不是raft,有关更多细节,请参见oz社区。在运行默认协商一致伊斯坦布尔BFT时,我可以使用Tru显和OpenZeppelin SDK部署合同并与其进行交互。 当我切换到RAFT时,我无法使用松露迁移或contract部署合同。我没有看到任何不同的,我需要做配置方面的文件为筏。@abcoathup
https://stackoverflow.com/questions/54128954
复制相似问题