Sending Payments

Supply chain projects might benefit from the built-in payment solution, where payments for certain services and goods can be sent between supply chain participants.

One possible use case could be when retailers or end consumers send payments to the producers, logistics and fulfillment providers for the ordered assets.

Since none of the Hyperledger projects support cryptocurrency or any other type of payments, IOTA connector can be used to perform fee-less payments between participants at the moment where a smart contract confirms successful transaction.

To send payment using the IOTA wallet, you will need to store wallet seed and keyIndex on the ledger. Seed is used to initiate a transaction, and keyIndex is specific for IOTA implementation and represents the index of the current wallet address, which holds the tokens.

After every outgoing payment transaction, the remaining tokens are transferred to the next address in order to prevent double-spending. The index of the new address (called remainderAddress) should be stored on the ledger and used for the next outgoing payment. Incoming payments do not trigger address or index change.

In the example, we will maintain only one wallet for outgoing payments. This wallet will be assigned to the retailer, who is the end consumer of the asset in this supply chain project.

The payment will be sent to the previous asset holder each time the holder is changed, which indicates asset movement towards the end consumer. In other words, once a producer prepares a container for shipment and transfer it over to a freight forwarder, the retailer will pay to the producer in IOTA tokens. Then, once a freight forwarder delivers the container to the next destination, the retailer will transfer IOTA tokens to pay for this service.

All possible participants in this sample of a supply chain project are defined upon initialisation of the ledger. For simplicity, we assume that there is only one participant with the role of “Producer”, “Shipper” and so on.

We will start with the definition of the structure for the wallet object

This structure contains seed and keyIndex as described above. In addition, it also contains the actual address where tokens are currently stored. You can perform balance check to ensure sufficient balance of the wallet. Enter your wallet address on this page to check the current balance.

Next, we will extend the existing Participant structure by adding the IotaWallet part into it

And then we will generate a new empty wallet and add wallet information to every participant record.

To generate a new wallet, you can use a function from the IOTA connector:

walletAddress, walletSeed := iota.CreateWallet()

Since we generate a new wallet for every record, we set the keyIndex value to 0. If you are about to use existing wallets, please adjust keyIndex values accordingly.

The generated wallets are empty and currently can only receive IOTA tokens.

In order to send tokens, you need to maintain at least one wallet funded with IOTA tokens.

Wallet data of this wallet should be stored on the ledger.

You can provide wallet data upon ledger initialisation, or you can modify values in the configuration file under chaincode/iota/config.go

To store a wallet on the ledger, please update the initLedger() function by adding the following code. You can replace values for iota.DefaultWalletSeed and iota.DefaultWalletKeyIndex with respective values of your wallet.