启动容器来执行geth命令
root@ubu-blockchain2:~# docker run -i blockchain101/ethereum-geth:1.6.5 geth attach http://45.32.252.88:8201
Welcome to the Geth JavaScript console!
instance: Geth/01/v1.6.5-stable/linux-amd64/go1.8
coinbase: 0x4c57e7e9c2f728046ddc6e96052056a241bdbd0a
at block: 6064 (Wed, 02 Aug 2017 01:13:50 UTC)
datadir: /ethcluster/779977/data/01
modules: admin:1.0 eth:1.0 net:1.0 rpc:1.0 web3:1.0
查看我们的账户和余额
eth.getBalance(eth.accounts[0])
11000000000000000000
eth.getBalance(eth.accounts[1])
0
eth.accounts[0]
"0x4c57e7e9c2f728046ddc6e96052056a241bdbd0a"
> eth.accounts[1]
"0xe82e2f0a5abd8774767b9751659976f9c4f59181"
发起一笔交易
eth.sendTransaction({
from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(3,'ether')})
"0x0075da712d26aea17d6647035107f509e13eaf3d113c1577db14d4cc4216caec"
查看交易细节
> eth.getTransaction("0x0075da712d26aea17d6647035107f509e13eaf3d113c1577db14d4cc4216caec")
{
blockHash: "0x3115703894dc6015c96ef4de3e5615f416498ca1f985902b38cd70e27dab8871",
blockNumber: 1250,
from: "0x4c57e7e9c2f728046ddc6e96052056a241bdbd0a",
gas: 90000,
gasPrice: 18000000000,
hash: "0x0075da712d26aea17d6647035107f509e13eaf3d113c1577db14d4cc4216caec",
input: "0x",
nonce: 0,
r: "0x2aef2c1fa03a0fa4172d21e3383d8c0431d45ec855b9d16efdd5eb2de90c414c",
s: "0xc4d530fb7902bf509fe56bfbea4861bf6cc16791afc9c9103c1a18f77407d1f",
to: "0xe82e2f0a5abd8774767b9751659976f9c4f59181",
transactionIndex: 0,
v: "0x17cdb6",
value: 3000000000000000000
}
> eth.getBalance(eth.accounts[1])
3000000000000000000
验证用户0的余额
> eth.getBalance(eth.accounts[0])
7999622000000000000
编写一个简单的合约
contract Sample {
uint public value;
function Sample(uint v){
value=v;
}
function set(uint v){
value=v;
}
function get() constant returns (uint){
return value;
}
}
在remix网页编译得到ABI接口和合约的二进制代码、
abi=[{
"constant":true,"inputs":[],"name":"value","outputs":[{
"name":"","type":"uint256"}],"payable":false,"type":"function"},{
"constant":false,"inputs":[{
"name":"v","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{
"constant":true,"inputs":[],"name":"get","outputs":[{
"name":"","type":"uint256"}],"payable":false,"type":"function"},{
"inputs":[{
"name":"v","type":"uint256"}],"payable":false,"type":"constructor"}]
[{
constant: true,
inputs: [],
name: "value",
outputs: [{
name: "",
type: "uint256"
}],
payable: false,
type: "function"
}, {
constant: false,
inputs: [{
name: "v",
type: "uint256"
}],
name: "set",
outputs: [],
payable: false,
type: "function"
}, {
constant: true,
inputs: [],
name: "get",
outputs: [{
name: "",
type: "uint256"
}],
payable: false,
type: "function"
}, {
inputs: [{
name: "v",
type: "uint256"
}],
payable: false,
type: "constructor"
}]
需要使用eth.contract来定义一个合约类
> sample=eth.contract(abi)
{
abi: [{
constant: true,
inputs: [],
name: "value",
outputs: [{...}],
payable: false,
type: "function"
}, {
constant: false,
inputs: [{...}],
name: "set",
outputs: [],