$ docker build -t hd-coop .
$ docker run -it --name hd-coop -p 8545:8545 -p 80:80 hd-coop
$ docker run -it --name hd-coop -p 8545:8545 -p 80:80 ubuntu:latest
$ apt-get update
$ apt-get install software-properties-common git curl nginx vim
$ add-apt-repository -y ppa:ethereum/ethereum
$ apt-get update
$ apt-get install ethereum
$ apt-get install solc
$ geth account new
. Save the id somewhere for later.
$ puppeth
Please specify a network name to administer (no spaces or hyphens, please)
> hdcoop
What would you like to do? (default = stats)
1. Show network stats
2. Configure new genesis
3. Track new remote server
4. Deploy network components
> 2
Which consensus engine to use? (default = clique)
1. Ethash - proof-of-work
2. Clique - proof-of-authority
> 2
How many seconds should blocks take? (default = 15)
> (press enter)
Which accounts are allowed to seal? (mandatory at least one)
> 0xddaebdd6966bf50584b73f14e07a5fd0754207b2 (replace with your account id)
> 0x
Which accounts should be pre-funded? (advisable at least one)
> 0xddaebdd6966bf50584b73f14e07a5fd0754207b2
> 0x
Specify your chain/network ID if you want an explicit one (default = random)
> (press enter)
What would you like to do? (default = stats)
1. Show network stats
2. Manage existing genesis
3. Track new remote server
4. Deploy network components
> 2
1. Modify existing fork rules
2. Export genesis configuration
3. Remove genesis configuration
> 2
Which file to save the genesis into? (default = hdcoop.json)
> (press enter)
press ctrl + C to stop and exit from the puppeth wizard process
$ geth init hd-coop.json
$ git clone https://github.com/hackersanddesigners/coop.git
$ cd coop/ && solc -o target --bin --abi coop.sol
$ echo <YOUR_PASSPHRASE> >> gethpass
$ geth --unlock <geth-account> --password /root/gethpass --mine --rpc --rpcapi "eth,net,web3,admin,personal" console 2>> geth.log
> var coopFactory = eth.contract(<contents of the file coop.abi>)
> var coopCompiled = "0x" + "<contents of the file coop.bin>"
> var _budget = 10000;
> var coop = coopFactory.new(_budget, { from: eth.coinbase, data:coopCompiled gas: 4000000 }, function(e, contract) {
if(!e) {
if(!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
} else {
console.log(e);
}
})
IMPORTANT make note of the address that pops out once the contract is mined. You are going to need it later.
> personal.newAccount("password")
> eth.sendTransaction({from:eth.coinbase, to:eth.accounts[1], value: web3.toWei(1.0, "ether")})
exports.creds = {
"jbg": {
"pwd": "password",
"addr": "0x4e858..."
},
"selby": {
"pwd": "password",
"addr": "0xd8852..."
},
"anja": {
"pwd": "password",
"addr": "0x27c84..."
},
"andre": {
"pwd": "password",
"addr": "0x000a2..."
},
"juliette": {
"pwd": "password",
"addr": "0xd939a..."
},
"heerko": {
"pwd": "password",
"addr": "0xd092d..."
}
};
and replace the "addr" bits with the accounts created in Geth, and the password with the passwords you gave to Geth.
cd ~/coop
and do git clone https://github.com/hackersanddesigners/coopserv.git
Set exports.abi =
to the content of Coop.abi in the target directory created during the solc
step.
Set exports.contractAddress =
to the address that you took note of earlier, that popped up after the contract was mined.
$ curl -sL https://deb.nodesource.com/setup_8.x | bash -
$ apt-get install -y nodejs
or
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
$ export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
$ nvm install 8
(install app dependencies listed in package.json
)
$ npm install
$ node server.js
Add a proxy pass for the node.js server.
location /api {
proxy_pass http://localhost:3000;
}
$ nginx
/root/
|___ gethpass
|___ hdcoop.json
|___ get.log
|___ coop/
|___ target
|___ coopserv
$ docker start -ia hd-coop
$ docker exec -it hd-coop bash
> personal.unlockAccount(eth.coinbase, "password")
> eth.getBalance(eth.coinbase)
> miner.start()
> miner.stop()
> eth.getBlock("latest")
> var abi = <ABI from either the target dir of compiling, or abi.js in the coopserv project>
> var contract = web3.eth.contract(abi)
> var instance = contract.at('<contract address when the contract was mined, check address.js of coopserv project>')
> instance.budget()
> instance.deactivateMember(<member address, ex. "0x4e858efead93c4e749bf2e58848452f4cb7c7bdc", { from: <member address, ex. "0x4e858efead93c4e749bf2e58848452f4cb7c7bdc"> })
The from
is actually important there, otherwise you will get a Invalid Address Error.
You can also set:
> eth.defaultAccount = eth.coinbase
...if you want to avoid setting the from
.
Once you execute a transaction or function, you will get another hash back. You can use that hash to check the status of the transaction:
> eth.getTransactionReceipt("0xc7c63b67747c0c825229ce3d36d226423adb8cab6bebe12b6d5001e0dc3f79b3")
There is a status in the reply: 0x0
it failed, or 0x1
it succeeded.
$ curl --cookie-jar cookies.txt -d "name=jbg&pwd=password" "http://localhost/api/login"
$ curl --cookie cookies.txt -d "name=andre&addr=0x0f764540f362d1e88e59432cf1c130cd285c8155" "http://localhost/api/members"
$ curl --cookie cookies.txt -X POST "http://localhost/api/budget"
$curl --cookie cookies.txt -d "cost=1000&title=Fun&description=Yes" "http://localhost/api/activities"
$ nginx -s stop
To access already existing docker image:
docker start -ia hd-coop
or if already running:
docker exec -it hd-coop bash
Then to start mining:
cd ~ && geth --unlock <geth-account-id> --password /root/gethpass --mine --rpc --rpcapi "eth,net,web3,admin,personal" console 2>> geth.log
Open new terminal window and do:
docker exec -it hd-coop bash
tail -f geth.log
Open new terminal window and do:
docker exec -it hd-coop bash
cd ~/coopserv/ && node server.js
- if problems when running the server:
ps aux | grep node
pkill node
- if problems when running the server: