-
Notifications
You must be signed in to change notification settings - Fork 8
/
greeter.js
30 lines (23 loc) · 6.73 KB
/
greeter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*******************************************************************************
* Copyright © 2018 Software AG, Darmstadt, Germany and/or its licensors
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*******************************************************************************/
var greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":true,"type":"constructor"}]);
var greeterGas = web3.eth.estimateGas({data: '0x60606040526040516103183803806103188339810160405280805190910190505b5b60008054600160a060020a03191633600160a060020a03161790555b6001818051610050929160200190610058565b505b506100f8565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009957805160ff19168380011785556100c6565b828001600101855582156100c6579182015b828111156100c65782518255916020019190600101906100ab565b5b506100d39291506100d7565b5090565b6100f591905b808211156100d357600081556001016100dd565b5090565b90565b610211806101076000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166341c0e1b58114610048578063cfae32171461005d575b600080fd5b341561005357600080fd5b61005b6100e8565b005b341561006857600080fd5b61007061012a565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100ad5780820151818401525b602001610094565b50505050905090810190601f1680156100da5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000543373ffffffffffffffffffffffffffffffffffffffff908116911614156101275760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b6101326101d3565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101c85780601f1061019d576101008083540402835291602001916101c8565b820191906000526020600020905b8154815290600101906020018083116101ab57829003601f168201915b505050505090505b90565b602060405190810160405260008152905600a165627a7a723058207f61741c6e67568aa389ab509d4787ddf575244b3eb502f59d16f1c62f2271000029'})*2;
var greeter = greeterContract.new("Hello Tom",{from: web3.eth.accounts[0], data: '0x60606040526040516103183803806103188339810160405280805190910190505b5b60008054600160a060020a03191633600160a060020a03161790555b6001818051610050929160200190610058565b505b506100f8565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009957805160ff19168380011785556100c6565b828001600101855582156100c6579182015b828111156100c65782518255916020019190600101906100ab565b5b506100d39291506100d7565b5090565b6100f591905b808211156100d357600081556001016100dd565b5090565b90565b610211806101076000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166341c0e1b58114610048578063cfae32171461005d575b600080fd5b341561005357600080fd5b61005b6100e8565b005b341561006857600080fd5b61007061012a565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100ad5780820151818401525b602001610094565b50505050905090810190601f1680156100da5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000543373ffffffffffffffffffffffffffffffffffffffff908116911614156101275760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b6101326101d3565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101c85780601f1061019d576101008083540402835291602001916101c8565b820191906000526020600020905b8154815290600101906020018083116101ab57829003601f168201915b505050505090505b90565b602060405190810160405260008152905600a165627a7a723058207f61741c6e67568aa389ab509d4787ddf575244b3eb502f59d16f1c62f2271000029',gas: greeterGas }, function (e, contract){console.log(e, contract);if (typeof contract.address !== 'undefined') {console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);}});
var mortalContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":true,"type":"constructor"}]);
var mortalGas = web3.eth.estimateGas({data: '0x60606040525b60008054600160a060020a03191633600160a060020a03161790555b5b60bb806100306000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166341c0e1b58114603c575b600080fd5b3415604657600080fd5b604c604e565b005b6000543373ffffffffffffffffffffffffffffffffffffffff90811691161415608c5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820e3e270667e4cccb8d5a48061960e30adb71f41a3e7798fd46f7ca802027676700029'})*2;
var mortal = mortalContract.new({from: web3.eth.accounts[0], data: '0x60606040525b60008054600160a060020a03191633600160a060020a03161790555b5b60bb806100306000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166341c0e1b58114603c575b600080fd5b3415604657600080fd5b604c604e565b005b6000543373ffffffffffffffffffffffffffffffffffffffff90811691161415608c5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820e3e270667e4cccb8d5a48061960e30adb71f41a3e7798fd46f7ca802027676700029',gas: mortalGas }, function (e, contract){console.log(e, contract);if (typeof contract.address !== 'undefined') {console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);}});
// replace all <parm1,parm2...,parmn> with the actual values before loading this script
// in geth: run loadScript("greeter.js"); and wait ...
// if a contract cannot be mined -> play with the gas
// run the following commands in geth to enable contract:
// personal.unlockAccount(web3.eth.accounts[0], "yourPassword")
// eth.getCode(<your contract>.address) -> if you see anything else than "0x" you are there ...
// run in geth: <your contract>.<your contracts method>(<params>) to see it working ...
// to view contract mining: run txpool.status ...
// if you get 'Error: invalid address': provide an address as input var like {from:eth.accounts[0]} ...