Ethereum 使用web3部署智能合约时不支持同步请求

Ethereum 使用web3部署智能合约时不支持同步请求,ethereum,smartcontracts,truffle,web3js,web3,Ethereum,Smartcontracts,Truffle,Web3js,Web3,我正在尝试使用Web3、Truffle和Testrpc在本地部署智能合约。我使用Truffle编译了一个智能合约,并使用以下代码来提取ABI和字节码。在同一个脚本中,我尝试使用web3.eth.contract.deploy(在本文档中给出:)部署合同,但出现以下错误: Error: Synchronous requests are not supported 我该怎么做才能避开这个问题 以下是供参考的脚本: let fs = require("fs"); let Web3 = require

我正在尝试使用Web3、Truffle和Testrpc在本地部署智能合约。我使用Truffle编译了一个智能合约,并使用以下代码来提取ABI和字节码。在同一个脚本中,我尝试使用web3.eth.contract.deploy(在本文档中给出:)部署合同,但出现以下错误:

Error: Synchronous requests are not supported
我该怎么做才能避开这个问题

以下是供参考的脚本:

let fs = require("fs");
let Web3 = require('web3'); // https://www.npmjs.com/package/web3
var TestRPC = require("ethereumjs-testrpc");

let web3 = new Web3();
web3.setProvider(TestRPC.provider());

let source = fs.readFileSync("../SmartContracts/build/contracts/TheContract.json");
let JSONObject = JSON.parse(source);

// ABI and bytecode description as JSON structure
let abi = JSONObject.abi
let bytecode = JSONObject.unlinked_binary;

// Create Contract proxy class
let contractSettings = {
  from: addr, 
  gas: 1000000, 
  data: bytecode
}
let SampleContract = new web3.eth.Contract(abi, contractSettings);

let deploySettings = {
  data: bytecode,
  from: addr
}

SampleContract.deploy(deploySettings)
  .send({
    from: addr,
    gas: 1500000,
    gasPrice: '30000000000000'
  })
  .on('error', function(error){ 
    console.log("error");
  })
  .on('transactionHash', function(transactionHash){ 
    console.log("transaction hash");
  })
  .on('receipt', function(receipt){
    console.log("receipt") // contains the new contract address
  })
  .on('confirmation', function(confirmationNumber, receipt){ 
    console.log("confirmation");
  })
  .then(function(newContractInstance){
    console.log(newContractInstance.options.address) // instance with the new contract address
  });

控制台日志(“完成”)

我认为这是使用TestRPC作为web3提供程序的一个问题。切换到本地geth实例似乎解决了问题。

您最终找到了解决方案吗?我也有同样的问题。是的,我相信你是对的。我也有这个问题,我相信这只是版本控制问题。我在这里打开它: