Smart Contract kann nicht mit Node JS (nicht Truffle) bereitgestellt werden

Hier ist der Code, wie er in web3 doc(node:13887) erklärt wird.

 web3.eth.estimateGas({data: '0x' + bytecode}).then(value=>{
 console.log('gasEstimate = ' + value);
 let MyContract = new web3.eth.Contract(abi,{
          from: publicKey,//user wallet 
          gasPrice: '10000000000000',
          gas: value
         });
 console.log('deploying contract...');
 MyContract.deploy().send(function(error, transactionHash){
  }).on('error', function(error){ })
    .on('transactionHash', function(transactionHash){ })
    .on('receipt', function(receipt){
     console.log(receipt.contractAddress) // contains the new contract address   })
    .on('confirmation', function(confirmationNumber, receipt){  })
    .then(function(newContractInstance){
    console.log(newContractInstance.options.address) // instance with the new contract address
   });
});

hier ist die fehlermeldung

UnhandledPromiseRejectionWarning: Error: Request failed with status code 522
at createError (/home/project/node_modules/axios/lib/core/createError.js:16:15)
at settle (/home/project/node_modules/axios/lib/core/settle.js:18:12)
at IncomingMessage.handleStreamEnd (/home/project/node_modules/axios/lib/adapters/http.js:201:11)
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)
(node:13887) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:13887) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

BEARBEITEN

Dank all dem funktioniert der Code

  web3.eth.estimateGas({data: '0x' + bytecode}).then(value=>{
  let MyContract = new web3.eth.Contract(abi,{
     from: publicKey,
     gasPrice: 1000000,
     gas: value
   });
  MyContract.deploy({
       data:  '0x' +   bytecode
       }).send({
               from: publicKey,
               gasPrice: 1000000,
               gas: value
      },function(error, transactionHash){})
        .on('error', function(error){ })
        .on('transactionHash', function(transactionHash){ })
        .on('receipt', function(receipt){})
        .on('confirmation', function(confirmationNumber, receipt){  })
        .then(function(newContractInstance){ });
        });
Ich denke, Sie müssen MyContract.deploy()durch (await MyContract.deploy())... ersetzen und natürlich die gesamte Funktion deklarieren async.
@goodvibration Der Code verwendet die Versprechen, schauthen
MyContract.deploy({Daten: '0x' + Bytecode})

Antworten (2)

Sie haben vergessen, die Informationen zu senden, die für die Bereitstellung des Vertrags erforderlich sind. Laut Dokument müssen Sie der Funktion den Bytecode und die Argumente des Konstruktors Ihres Vertrags zur Verfügung stellen deploy.

myContract.deploy({
    data: '0x12345...',
    arguments: [123, 'My String']
})
.send({
    from: '0x1234567890123456789012345678901234567891',
    gas: 1500000,
    gasPrice: '30000000000000'
}, function(error, transactionHash){ ... })
.on('error', function(error){ ... })
.on('transactionHash', function(transactionHash){ ... })
.on('receipt', function(receipt){
   console.log(receipt.contractAddress) // contains the new contract address
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.then(function(newContractInstance){
    console.log(newContractInstance.options.address) // instance with the new contract address
});
Ich habe diesen Teil hier let MyContract = new web3.eth.Contract(abi,{ from: publicKey, gasPrice: value, gas: '10000000000000' });
Ich kann dort keinen Bytecode sehen. Um den Vertrag in der Blockchain bereitzustellen, müssen Sie den Bytecode senden. Sie initialisieren gerade ein Objekt mit der abi-Schnittstelle

Statuscode 522 ist HTTP-Verbindungszeitüberschreitung. Überprüfen Sie, ob Sie den Anbieter und die erstellte web3-Instanz korrekt eingestellt haben. Überprüfen Sie auch Ihren Internetstatus.

Ich habe ein richtiges Internet, da die Blockchain synchronisiert wird, und eine Web3-Instanz, da ich Ether an den Ersteller sende, damit er Ether für Vertragsgas hat
@goodvibration - das ist das Beispiel aus web3 docs
Du hast Recht. Ich war im Moment auf der Web3-Oberfläche verwirrt.
Denke @mirg hat Recht
node v 8.11.2 Anbieter rinkeby testne auf unserem Server
Ich meine Ethereum-Netzwerkknoten wie Geth oder Parity, nicht NodeJS.
geth-VERSION: 1.8.4-unstable-a095b84e
Wenn die Lösung von @mirg nicht funktioniert, schlage ich vor, zu versuchen, Ihr Geth auf den neuesten Stable zu aktualisieren.
Ich bin mir nicht sicher, warum ich all diese Details angeben soll, wenn sie bereits im neuen web3.eth.Contract enthalten sind (hier)
ABI, das Sie in den Vertrag übergeben, unterscheidet sich vom Bytecode. Das eigentliche, was an das Netzwerk verteilt wird, ist der Bycode, den Sie kompiliert haben. ABI ist nur eine Schnittstelle für die Interaktion mit diesem Bycode.
wo genau muss ich abi haben ? myContract.deploy({ data: '0x12345...', arguments: [123, 'My String'] }) als Wert für data -key ?
Du hast es bereits getan, let MyContract = new web3.eth.Contract(abi, .... Was Sie tun müssen, ist genau das, was mirg gesagt hat. Versuchen Sie einfach, die Daten wie contract.deploy ({data: your_bytecode}) zu übergeben. Wenn Sie Konstruktorargumente haben, übergeben Sie Argumente.