GithubHelp home page GithubHelp logo

beelis / web3j_tests Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matthiaszimmermann/web3j_tests

0.0 2.0 0.0 48 KB

External tests for the web3j Java library

License: MIT License

Go 33.86% Java 66.14%

web3j_tests's Introduction

how to create a docker container that features the testrpc in memory chain and a solidity compiler

--- write docker file ---
see file Dockerfile in this git repository

--- build docker image ---
mzi@box ~/
$ eval $(docker-machine env default --shell=bash)

// change to directory that contains the Dockerfile
mzi@box ~/
$ docker build -t testrpc_solc .

// if docker build fails: restart the vm box and the docker deamon and try again 

$ docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
testrpc_solc                                    latest              d24ca6a8a2a7        13 days ago         602.5 MB

--- start container ---
mzi@box ~/
$ docker run -it -p 8545:8545 -d testrpc_solc

mzi@box ~/
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
eb1bc60fb600        testrpc_solc        "testrpc"           13 days ago         Up 13 days          0.0.0.0:8545->8545/tcp   goofy_mc

--- check container and installed components
mzi@box ~/
$ docker exec -it <container-id> bash

root@<container-id>:/# node -v
v6.9.5
root@<container-id>:/# npm list -g --depth=0
/usr/lib
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

--- test container using both testrpc + solc ---
mzi@box ~/
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_compileSolidity","params":["pragma solidity ^0.4.0; contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"],"id":1}' <ip-of-your-docker-box>:8545

this command should return someting along the following lines

{"id":1,"jsonrpc":"2.0","result":{"code":"0x6060604052346000575b60458060156000396000f3606060405260e060020a6000350463c6888fa18114601c575b6000565b346000576029600435603
b565b60408051918252519081900360200190f35b600781025b91905056","info":{"source":"pragma solidity ^0.4.0; contract test { function multiply(uint a) returns(uint d) { re
turn a * 7; } }","language":"Solidity","languageVersion":"0.4.6+commit.2dabbdf0.Emscripten.clang","compilerVersion":"0.4.6+commit.2dabbdf0.Emscripten.clang","abiDefi
nition":[{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"multiply","outputs":[{"name":"d","type":"uint256"}],"payable":false,"type":"function"}],"
userDoc":{"methods":{}},"developerDoc":{"methods":{}}}}}

--- test container using both testrpc and web3 javascript api

mzi@box ~/
$ docker ps
CONTAINER ID        IMAGE
b5c770d21bca        testrpc_solc

// enter running testrpc_solc container
mzi@box ~/
docker exec -it b5c770d21bca bash 

// in bash shell inside container: add node (should already be in the container though. TODO: check what's wrong ...)
root@b5c770d21bca:/# npm install web3

// start node from bash console
root@b5c770d21bca:/# node

// in node console: play around with web3 javascript api
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
console.log(web3.isConnected());
console.log(web3.fromWei(web3.eth.gasPrice, 'wei').toString());
console.log(web3.eth.accounts);
console.log(web3.eth.coinbase);
console.log(web3.fromWei(web3.eth.getBalance(web3.eth.coinbase), 'wei').toString());
console.log(web3.fromWei(web3.eth.getBalance(web3.eth.coinbase), 'ether').toString());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.