Ich habe versucht, den folgenden Vertrag zu erstellen geth
:
pragma solidity ^0.4.8;
contract Test {
uint256 public value;
function Test() {
value = 123;
}
}
Verwenden Sie die folgenden Befehle für die reduzierte Quelle:
> var testSource = "pragma solidity ^0.4.8; contract Test { uint256 public value; function Test() { value = 123; } }";
undefined
> var testCompiled = web3.eth.compile.solidity(testSource);
Error: The method eth_compileSolidity does not exist/is not available
at web3.js:3104:20
at web3.js:6191:15
at web3.js:5004:36
at <anonymous>:1:20
Wie in eth_compilers, eth_compileSolidity beschrieben, gibt es in go-ethereum 1.6.0 #3793 keine Möglichkeit mehr, die Solidity-Quellen zu kompilieren geth
.
Wie kann ich meinen Solidity-Quellcode kompilieren?
Verwenden Sie Remix von https://ethereum.github.io/browser-solidity :
Kopieren Sie die Web3-Bereitstellungsanweisungen von der Remix-Seite:
var untitled_testContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);
var untitled_test = untitled_testContract.new(
{
from: web3.eth.accounts[0],
data: '0x60606040523415600b57fe5b5b607b6000819055505b5b608f806100246000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b600054815600a165627a7a72305820a4fac284b98d43538f802082b0db8c67ddd6d72df4e8d9fbccb4cec0e52ea0df0029',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
Und fügen Sie es geth console
mit einem entsperrten Konto in das ein:
> personal.unlockAccount(eth.accounts[0], "{top secret password}");
true
> var untitled_testContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]);
"0xe22dc29e3e05d3206d9636ae7cba87a2827e7b3ef28c6e8e6d2ad49a14ba3ce9"
var untitled_test = untitled_testContract.new(
{
from: web3.eth.accounts[0],
data: '0x60606040523415600b57fe5b5b607b6000819055505b5b608f806100246000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b600054815600a165627a7a72305820a4fac284b98d43538f802082b0db8c67ddd6d72df4e8d9fbccb4cec0e52ea0df0029',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
$ more Test.sol
pragma solidity ^0.4.8;
contract Test {
uint256 public value;
function Test() {
value = 123;
}
}
Kompilieren Sie Test.sol im .json-Format, weisen Sie die Daten einer JavaScript-Variablen zu und senden Sie die Ausgabe in eine Datei:
$ echo "var testOutput=`solc --optimize --combined-json abi,bin,interface Test.sol`" > test.js
$ cat test.js
var testOutput={"contracts":{"Test.sol:Test":{"abi":"[{\"constant\":true,\"inputs\":[],\"name\":\"value\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"type\":\"constructor\"}]","bin":"60606040523415600b57fe5b5b607b6000819055505b5b608f806100246000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b600054815600a165627a7a72305820d0e71d151634ac6ae7626860a17881104022e5cd6d3a088eb8f941d9aa8e3bd20029"}},"version":"0.4.9+commit.364da425.Darwin.appleclang"}
Laden Sie in geth
den Inhalt von test.js:
$ geth console
...
> loadScript("test.js")
true
> testOutput
{
contracts: {
Test.sol:Test: {
abi: "[{\"constant\":true,\"inputs\":[],\"name\":\"value\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"type\":\"constructor\"}]",
bin: "60606040523415600b57fe5b5b607b6000819055505b5b608f806100246000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514603a575bfe5b3415604157fe5b6047605d565b6040518082815260200191505060405180910390f35b600054815600a165627a7a72305820d0e71d151634ac6ae7626860a17881104022e5cd6d3a088eb8f941d9aa8e3bd20029"
}
},
version: "0.4.9+commit.364da425.Darwin.appleclang"
}
> testOutput.contracts
{
abi: "[{\"constant\":true,\"inputs\":[],\"name\":\"value\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"type\":\"constructor\"}]",
...
> var testContract = web3.eth.contract(JSON.parse(testOutput.contracts["Test.sol:Test"].abi));
undefined
> personal.unlockAccount(eth.accounts[0], "{top secret password}");
true
> var test = testContract.new({ from: eth.accounts[0], data: "0x" + testOutput.contracts["Test.sol:Test"].bin, gas: 4700000},
function (e, contract) {
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
}
);
...
WEB3DEPLOY
AbschnittIch bin kürzlich auf das gleiche Problem gestoßen. Es gibt eine Vielzahl von Problemumgehungen, aber hier ist die Methode, die ich angewendet habe. Dies ist nicht unbedingt der beste Ansatz.
So generieren Sie Bytecode:
> solc --bin soliditySource.sol
So generieren Sie ABI:
> solc --abi soliditySource.sol
Dann mit Ihrem neu generierten bytecode
und abi
in geth 1.6:
var abi = <abi from solc>;
var myContract = eth.contract(abi);
var bytecode = '0x' + <bytecode from solc>;
var txDeploy = {from:eth.coinbase, data: bytecode, gas: 1000000};
var myContractPartialInstance = myContract.new(txDeploy);
// Mine block containing transaction...
var myContractInstance = myContract.at(myContractPartialInstance.address);
JSON.parse
. Außerdem muss das Konto möglicherweise zuerst mit zB entsperrt werden. personal.unlockAccount(eth.accounts[0])
.Vielleicht ziehen Sie es in Betracht, truffle
stattdessen das Framework herunterzuladen. Mit dem Truffle-Framework kann ich meine Dateien einfach kompilieren, aber auch speichern (es erledigt das für mich).
truffle
Sobald Sie mit dem Befehl heruntergeladen haben
npm i -g truffle
Sie können einfach mit dem Befehl kompilieren truffle compile
.
Nachdem ich mich ein paar Tage lang mit veralteten Dokumenten herumgeschlagen habe, habe ich hier eine super einfache Version erstellt, die helfen könnte: https://alanbuxton.wordpress.com/2017/07/19/first-steps-with-ethereum -private-netzwerke-und-intelligente-verträge-auf-ubuntu-16-04/
Da Geth die Befehlszeilen-Compiler-Schnittstelle nach Version 1.6 als veraltet markierte, war ich lange verwirrt. Ich habe ein einfaches Tutorial geschrieben, um zu beschreiben, wie man einen Vertrag nach Geth 1.6 kompiliert und bereitstellt. Ich hoffe, dieses Tutorial wird Ihnen helfen. Depoly-Vertrag auf der privaten Kette
Erstellen Sie einen Smart Contract über die Befehlszeile https://www.ethereum.org/greeter
Sunil Kumar
Datenschutz ist ein Menschenrecht.eth