[英]Deploying smart contract web3 Invalid RPC response
I'm trying to deploy a contract on my node server as follows: 我正在尝试在节点服务器上部署合同,如下所示:
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
});
}
I've tried several things and read in the documentation but can't seem to find anything! 我尝试了几件事并阅读了文档,但似乎找不到任何东西! I'm sure I can't be the only person with this issue, I'm using web3@0.20.
我确定我不是唯一一个遇到此问题的人,我使用的是web3@0.20。
If anyone can help I'd really appreciate it. 如果有人可以提供帮助,我将非常感激。
Two issues I can spot: 我可以发现两个问题:
challenger
's private key), so it can't sign a transaction for you. challenger
的私钥),因此它无法为您签署交易。 If challenger
is your account, then you can hold the key and sign the deployment transaction before broadcasting it. challenger
是您的帐户,则可以在广播之前按住密钥并签署部署事务。 If challenger
is a user of your app, you're better off having the user sign and send the transaction themselves via something like MetaMask . challenger
是您应用程序的用户,那么最好让用户签名并通过MetaMask之类的东西自己发送交易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.