Es scheint, dass dies ein sehr häufiges Thema ist, aber ich konnte die Lösung in anderen Fragen nicht finden, entschuldigen Sie die erneute Frage. Ich folge einem Anfängerbeispiel und versuche, einen Vertrag im Rinkeby-Netzwerk über den Infura-Knoten bereitzustellen.
Dies ist der Vertrag, den ich bereitstellen möchte:
pragma solidity ^0.4.22;
contract Inbox {
string public message;
constructor(string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
Dies ist die Deploy.js
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
' //Mnemonic ',
'https://rinkeby.infura.io/3qmjTiDl43PDhvdhm4WB'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Deploy from account', accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({ gas: '1000000', from: accounts[0] });
console.log('Contract deployed to', result.options.address);
};
deploy();
Wenn ich node deploy.js versuche, druckt die Konsole das erste Console.log der Deploy-Funktion, aber nach dem Warten heißt es:
(node:13776) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The contract code couldn't be stored, please check your gas limit.
(node:13776) [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.
Ich hoffe, ihr könnt mir helfen, tut mir leid, wenn es eine ganz leichte Sache ist, es zu lernen.
Wie hast du den Bytecode bekommen? Hat es das '0x' am Anfang?
Können Sie versuchen, das „0x“ hinzuzufügen, wenn Sie die Transaktion übermitteln?
.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })
Wenn Sie '0x' vor den Bytecode setzen, wird davon ausgegangen, dass der Rest hexadezimal ist und in Ruhe gelassen wird.
Wenn kein '0x' vorhanden ist, wird die gesamte Zeichenfolge in hexadezimal konvertiert. Das ist schlecht, weil der Bytecode doppelt so groß und komplett falsch ist.
Badr Bellaj
gbiatturi
Ismael
gbiatturi
Ismael
.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })
Finn Rothacker
mirg
Finn Rothacker