The project goals are:
-
Implement an Ethereum Smart Contract called
SoccerManager(using Solidity programming language) and deploy it to Ethereum Blockchain running locally using ethereum/client-go docker image; -
Implement two
Spring Bootbackend applications,ethereum-apiandplayer-api, that uses Web3j library to communicate with Ethereum blockchain; -
Implement two
Reactfrontend applications,ethereum-uiandplayer-ui, that communicate to their respective backend application.
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
Ethereum Smart Contract is a program that runs on an EVM (Ethereum Virtual Machine) similar to a Java program that runs on JVM (Java Virtual Machine). A contract is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum Blockchain. Ethereum Smart Contracts are usually written in Solidity programming language.
In order to implement smart contracts we used Remix. It's a powerful, open source tool that helps you write contracts using Solidity straight from the browser.
-
SoccerManager
SoccerManageris a smart contract that handles soccer players. Once deployed, it has some pre-defined soccer players registered. Initially, the agent of those pre-defined players is the owner of the contract (the wallet address used to deploy the contract). Besides, only the owner of the contract can add players. Other wallets (agent wallets) can buy soccer players and, once it is done, the agent wallet becomes the owner of the player.
-
ethereum-api
Spring Bootapplication that communicates with Ethereum Blockchain, usingWeb3jlibrary.ethereum-apiprovides some endpoints to create a new wallet, transfer ether from one wallet to another, etc. -
player-api
Spring Bootapplication that callsSoccerManagersmart contractpublic functionsusingWeb3j. It exposes some endpoints so that you can buy a player, get info about the player, add players, etc.Some endpoints, such
POST /api/players/add, requires the use of the owner contract wallet, i.e, the wallet that was used to deploySoccerManagersmart contract. -
ethereum-ui (TODO)
Reactfrontend application that provides a User Interface so that we can create a wallet, check its balance, transfer ethereum to other wallets, etc. -
player-ui (TODO)
Reactfrontend application that provides a User Interface to easily play with Ethereum Blockchain andSoccerManagersmart contract. UsingWeb3j, it listens toPlayerAdded,PlayerUpdatedandPlayerBoughtevent emitted fromSoccerManagercontract (and some other logs from Ethereum Blockchain) and updates the screen on-the-fly. Besides,player-uicommunicates directly withplayer-apiwhenever it needs some information fromSoccerManagercontract.
In a terminal, run the docker command below. It starts a container in development mode and exposes Ethereum RPC API on port 8545.
docker run -d --rm --name ethereum \
-p 8545:8545 -p 30303:30303 \
ethereum/client-go:v1.9.25 \
--rpc --rpcaddr "0.0.0.0" --rpcapi="db,eth,net,web3,personal" --rpccorsdomain "*" --dev
Run the following
docker execcommand if you want to enter in theGeth’s interactive JavaScript console inside Docker container. It provides a lot of features such as: create a wallet, check waller balance, transfer ether from one address to another, etc. We won't focus on it because we've decided to implement such features inethereum-apiusingWeb3j. In order to get more information visite Geth JavaScript console documentationdocker exec -it ethereum geth attach ipc:/tmp/geth.ipc
-
Access https://github.com/web3j/web3j/releases/tag/v4.5.5 and download
web3j-4.5.5.zip -
Unzip it to your preferred location
-
In a terminal, navigate to
ethereum-springboot-reactroot folder -
Export to
WEB3J_PATHenvironment variable, the absolute path ofWeb3jwhere you have unzippedexport WEB3J_PATH=path/to/web3j-4.5.5 -
Run the following script. It will compile Solidity
SoccerManagercode,solidity/SoccerManager.sol. When the compilation finishes, it will produce the files:solidity/SoccerManager.abiandsolidity/SoccerManager.bin. Then, the script uses these two files to generate theSoccerManager.javainethereum-apiandplayer-api../compile-generate-soccermanager.sh
-
-
Open a new terminal and navigate to
ethereum-springboot-react/ethereum-apifolder -
Run following command to start application
./mvnw clean spring-boot:run -
Wait for it to start before continuing
-
-
-
In a terminal, make sure you are inside
ethereum-springboot-reactroot folder -
Create the
contract ownerwalletCONTRACT_OWNER_WALLET=$(curl -s -X POST "http://localhost:8080/api/wallets/create" \ -H "Content-Type: application/json" \ -d "{ \"password\": 123, \"initialBalance\": 10000000000000000000}" | jq '.') CONTRACT_OWNER_WALLET_FILE=$(echo $CONTRACT_OWNER_WALLET | jq -r '.file') CONTRACT_OWNER_WALLET_ADDR=$(echo $CONTRACT_OWNER_WALLET | jq -r '.address') -
To check
contract ownerwalletecho "CONTRACT_OWNER_WALLET=$CONTRACT_OWNER_WALLET" echo "CONTRACT_OWNER_WALLET_FILE=$CONTRACT_OWNER_WALLET_FILE" echo "CONTRACT_OWNER_WALLET_ADDR=$CONTRACT_OWNER_WALLET_ADDR" -
Deploy
SoccerManagercontract using thecontract ownerwalletETHEREUM_CONTRACT_SOCCERMANAGER_ADDRESS=$(curl -s \ -X POST "http://localhost:8080/api/contracts/deploy/soccerManager" \ -H "Content-Type: application/json" \ -d "{ \"password\": 123, \"file\": \"$CONTRACT_OWNER_WALLET_FILE\", \"gasPrice\": 1, \"gasLimit\": 3000000 }") -
To check
SoccerManagercontract addressecho "ETHEREUM_CONTRACT_SOCCERMANAGER_ADDRESS=$ETHEREUM_CONTRACT_SOCCERMANAGER_ADDRESS"
-
-
-
In a terminal, make sure you are inside
ethereum-springboot-react/player-apifolder -
Export to
ETHEREUM_CONTRACT_SOCCERMANAGER_ADDRESSenvironment variable theSoccerManagercontract address obtained at Deploy Smart Contract stepexport ETHEREUM_CONTRACT_SOCCERMANAGER_ADDRESS=... -
Run following command to start application
./mvnw clean spring-boot:run
-
| Application | URL |
|---|---|
ethereum-api |
http://localhost:8080/swagger-ui.html |
player-api |
http://localhost:8081/swagger-ui.html |
-
In a new terminal and inside
ethereum-springboot-reactroot folder, run the following commands to createnew agentwalletNEW_AGENT_WALLET=$(curl -s -X POST "http://localhost:8080/api/wallets/create" \ -H "Content-Type: application/json" \ -d "{ \"password\": 123, \"initialBalance\": 10000000000000000000}" | jq '.') NEW_AGENT_WALLET_FILE=$(echo $NEW_AGENT_WALLET | jq -r '.file') NEW_AGENT_WALLET_ADDR=$(echo $NEW_AGENT_WALLET | jq -r '.address') -
To check
new agentwalletecho "NEW_AGENT_WALLET = $NEW_AGENT_WALLET" echo "NEW_AGENT_WALLET_FILE = $NEW_AGENT_WALLET_FILE" echo "NEW_AGENT_WALLET_ADDR = $NEW_AGENT_WALLET_ADDR" -
Get player with id
1usingnew agentwalletcurl -s -X POST "http://localhost:8081/api/players/get" \ -H "Content-Type: application/json" \ -d "{ \"password\": 123, \"file\": \"$NEW_AGENT_WALLET_FILE\", \"gasPrice\": 1, \"gasLimit\": 3000000, \"playerId\": 1}" | jq '.' -
Buy player with id
1usingnew agentwalletcurl -s -X POST "http://localhost:8081/api/players/buy" \ -H "Content-Type: application/json" \ -d "{ \"password\": 123, \"file\": \"$NEW_AGENT_WALLET_FILE\", \"gasPrice\": 1, \"gasLimit\": 3000000, \"playerId\": 1, \"weiValue\": 1000000000000000000}" | jq '.' -
Get the players
new agenthascurl -s -X POST "http://localhost:8081/api/agents/players" \ -H "Content-Type: application/json" \ -d "{ \"password\": 123, \"file\": \"$NEW_AGENT_WALLET_FILE\", \"gasPrice\": 1, \"gasLimit\": 3000000}" | jq '.'
- To stop
ethereum-apiandplayer-api, just go to the terminals where they are running and pressCtrl+C - To stop
ethereum/client-godocker container, run the following command in a terminaldocker stop ethereum
- implement
ethereum-uiandplayer-ui


