Before you begin, you need to check that you have all the prerequisites installed as follows:
- OS: Linux (recommend: Ubuntu18.04 or CentOS7)
- Docker (recommend: v17.06.2-ce or greater)
- Docker-compose (recommend: v1.14.0 or greater)
- node.js v12 (recommend: v12.20.2 or greater)
- The ports 5034, 5040, 5051 are available (If they are already used, the following processes can be done by changing the port number setting)
- Before booting, please modify the following information for your environment
applicationHostInfo.hostName
(IP address of the host on the Location header) on/packages/config/default.json
- (Optional) Please modify the following information for your environment if necessary. This procedure should only be performed by users who cannot use port 5034.
applicationHostInfo.hostPort
(The port number of Routing-interface http server, the default is 5034) on/packages/config/default.json
- Go to the following directory:
cd cactus/examples/electricity-trade/
- Start ledgers:
./script-start-ledgers.sh
- Build validators, packages, and the cartrade app:
./script-build-all.sh
- Start validators and the cartrade app
- Please open three consoles and execute the following:.
- Start the validator for Sawtooth on the first console:
./script-start-validator-sawtooth.sh
- Start the validator for Ethereum on the second console:
./script-start-validator-ethereum.sh
- Start the cartrade app on the third console:
./script-start-electricity-trade.sh
- The parameters are used on this application
- Source account on Ethereum:
06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97
- The privkey of source account on Ethereum:
cb5d48d371916a4ea1627189d8af4f642a5d72746a06b559780c3f5932658207
- Destination account on Ethereum:
9d624f7995e8bd70251f8265f2f9f2b49f169c55
- The key name of intkey on Sawtooth:
MI000001
- Source account on Ethereum:
- Set the intkey script on Sawtooth docker:
./script-set-sawtooth-intkey.sh
- Register on account information:
curl localhost:5034/api/v1/bl/electricity-trade/meter/register/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"h40Q9eMD","meterParams":["MI000001", "06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97", "cb5d48d371916a4ea1627189d8af4f642a5d72746a06b559780c3f5932658207", "9d624f7995e8bd70251f8265f2f9f2b49f169c55"]}'
-
(Optional) Check the balance on Ethereum accounts using the following script
- Check the balance of the source account as the following:
curl localhost:5034/api/v1/bl/balance/06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97
- The result: `{"status":200,"amount":100000}`
- Check the balance of the destination account:
curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55
- The result: `{"status":200,"amount":0}`
-
Start the electricity-trade application
curl localhost:5034/api/v1/bl/electricity-trade/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"h40Q9eMD"}'
- The example response of tradeID: `{"tradeID":"20210220075755506-001"}`
- (Then, the application starts to monitor the Sawtooth blockchain)
-
Execute the intkey transaction on Sawtooth blockchain
- Open the docker bash:
docker exec -it sawtooth-shell-default bash
- Execute the intkey transaction:
intkey create_batch --key-name MI000001 --value-set 50 --value-inc 24 sawtooth batch submit -f batches.intkey --url http://rest-api:8008
- (In the above, the value of the key
MI000001
is set as 50, and increased by 24) - After that, exit the docker bash:
exit
- Open the docker bash:
-
(Optional) Check the balance on Ethereum accounts using the following script
- Check the balance of the source account as the following:
curl localhost:5034/api/v1/bl/balance/06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97
- The result: `{"status":200,"amount":99976}`
- Check the balance of the destination account:
curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55
- The result: `{"status":200,"amount":24}`
- (The result shows that the asset was transferred between Ethereum addresses depending on the value of the change in Sawtooth intkey.)