This sample application simulates energy trading between three individuals using divisible digital assets.
This sample application demonstrates how divisible assets can be traded on TBSP on Google Cloud Platform. Specifically, this sample application will simulate energy trading between three entities: Alice, Bob, and Charlie. Specifically, they are known as prosumers - consumers who have the ability to also produce energy.
In this scenario, there are three primary entities:
Alice and Bob can produce energy using the solar panels installed on the roofs of their houses. However, Charlie does not have a solar panel and requires energy from the others.
Excess energy produced by Alice and Bob can be sold to other entities.
The certification authority is the fourth entity and issues energy certificates to all entities participating in this energy exchange, which happens over a one-day period.
- The certification authority enables Alice, Bob, and Charlie to issue renewable energy certificates for the amounts. Here, Alice and Bob generated 10 and 6 kWh of energy respectively, while Charlie does not produce any energy. The issuing of the certificates results in the creation of a transaction ID.
- Charlie wants to buy renewable energy and asks Alice for the amount of 15 kWh.
- Alice tries to transfer her excess energy (10kWh), but she does not have the requested amount (15 kWh). She then asks Bob to transfer her the remaining 5 kWh.
- Bob transfers 5 kWh of power to Alice. This creates a transfer transaction with an ID.
- Aware of the change, the energy provider issuer now checks and confirms the new renewable energy certificates: Alice possesses 15 kWh, Bob has 1 kWh, and Charlie is still at 0 kWh.
- Alice then transfers Charlie 15 kWh. This creates another transfer transaction.
- In the end, the energy balance reflects the change: Alice is left with 0 kWh, Bob with 2 kWh, and Charlie has the desired 30 kWh.
In addition to retrieving the asset and transaction history, this sample application sample contains two important functions:
- Create a divisible digital asset
- Transfer a divisible digital asset
You can see the source code of this specific sample application here.
Run the sample application
In a terminal session, run the energy_trading sample found in folder ng-rt-digitalasset-sdk-samples: (alias: energyOneDay):
The following output will show an energy trading process:
[INFO] One day energy-trading
[INFO] Energy balance:Alice(0KWH),Bob(1KWH),Charlie(15KWH)
[INFO] Energy provider is creating a renewable-energy certificate with 2 outputs: 10KWH for Alice and 6KWH for Bob
[INFO] CREATE txId 2f06b0610208954bed38ea01965d2681196f170954f117b27ecb02b8e0282622
[INFO] Energy balance:Alice(10KWH),Bob(7KWH),Charlie(15KWH)
[INFO] Charlie wants to buy 15KWH
[INFO] Alice asks Bob to transfer her 5 of his 6 energy units from energy-certificate 2f06b061*
[INFO] Bob transfers Alice 5 energy units and gets 1 energy unit back from energy-certificate 2f06b061*
[INFO] TransferTx Id: 7f14cebd5fc78b439c16af35b56138139f8cc559616408838407afadca23e9e8
[INFO] Energy balance:Alice(15KWH),Bob(2KWH),Charlie(15KWH)
[INFO] Alice sends Charlie 15 energy units:
[INFO] 10 from tx 2f06b061* input index 0
[INFO] 5 from transferTxId 7f14cebd* input index 1
[INFO] TransferTx Id: a906e7d408e2dab4c2bdc9d7dce474be663f9a6f50101c089864cf5ec8f37341
[INFO] Energy balance:Alice(0KWH),Bob(2KWH),Charlie(30KWH)
Return to the main sample applications menu.