我正在尝试在我的节点服务器上部署合同,如下所示:
var escrow = 'pragma solidity ^0.4.4;contract Escrow {address public challenger;address public participant;address public arbiter;function Escrow(address _participant, address _arbiter) {challenger = msg.sender;participant = _participant;arbiter = _arbiter;}function payoutToParticipant() {if(msg.sender == challenger || msg.sender == arbiter) {participant.send(this.balance);}}function refundToChallenger() {if(msg.sender == challenger || msg.sender == arbiter) {challenger.send(this.balance);}}function getBalance() constant returns (uint) {return this.balance;}}';
module.exports.createEscrowContract = function(req, res) {
//Set variables
var challenger = '0xE6...';
var participant = '0x4E...';
var arbiter = '0xe5C...';
//Compile contract
var compiled = solc.compile(escrow);
console.log(compiled);
const web3 = new Web3();
web3.setProvider(new
web3.providers.HttpProvider("https://mainnet.infura.io/XXXX"));
//Store bytecode
var bytecode = compiled.contracts[':Escrow'].bytecode;
//Store abi
var abi = JSON.parse(compiled.contracts[':Escrow'].interface);
var escrowContract = web3.eth.contract(abi);
//Seems to compile fine.
console.log(escrowContract);
//Deploy contract
var deployed = escrowContract.new(participant, arbiter, {
from: challenger,
data: bytecode,
gas: 470000,
}, (error, contract) => {
console.log(error);
// Invalid JSON RPC response: ""
console.log(contract);
//undefined
});
}
我已经尝试了几件事并阅读了文档,但似乎找不到任何东西!我确定我不能是唯一遇到此问题的人,我使用的是 web3@0.20。
如果有人可以提供帮助,我将不胜感激。