# Blockchain: A Tale of Two Applications
## 3 Case Study--The \"CriptoSenhas\" Scenario
### CriptoSenhas Mobile Application
#### 3.3.3 Implementation Details  
The CriptoSenhas application provides the following features:  
* Show user account data (wallet)--account address, number of tokens (CriptoSenhas), details of the transactions that were sent;
* User Preferences--PIN code protection and the Ethereum network endpoint;
* Option to backup and remove an account (wallet);
* Show the account address through the \"Receive\" tab;
* Send CriptoSenhas through the \"Send\" tab. The following restrictions apply: only one account can be used per device; and only sent transactions can be seen. The Ethereum network endpoints do not provide the transaction history, and to avoid large processing in the client device, we have chosen to list only the transactions that were sent from the app. In Figure 16, we show the navigability diagram of the main structural change made to the previous structure described for the YABW application (Section 2.2):  
In Figure 16, we can see that there is no option to create more accounts, as in the context of this case study, the application was intended to be used by students from an educational institution, where each student would only have one account (wallet). _Invoking Smart Contract Methods_  
The Smart Contracts bytecode is stored in the Ethereum Blockchain in a binary format. In order to be able to use the Smart Contract CriptoSenhas, it is necessary to instantiate the contract with the Application Binary Interface (ABI) that describes the contract interface (as exemplified in Figure 17) and the contract address at the blockchain. Figure 16: Navigation Diagram of the initial view “CriptoSenhas” and of the transactions sent. Having access to the contract instance, it is possible to invoke the methods of this contract. However, there are two types of distinct operations: (1) transactions that require registration in Blockchain, such as a transaction of a token between two entities; and (2) operations that are not registered in Blockchain, such as checking the token amount of an address. The latter operations, which do not need to be registered in Blockchain, are simple and straightforward: the method is invoked, and a response is returned by an Ethereum network node. However, the operations that are registered in Blockchain are more complex, and, beyond invoking the method, it is necessary to:  
1. Estimate the gas limit to perform the method and the current average gas price in Ether. 2. Get the number of transactions already done;
3. Create the transaction object with the following parameters: 1. from: source address; 2. nonce: the number of transactions already done; 3. gasPrice: price per gas in Ether; 4. to: Smart Contract address; 5. value: amount of Ether to send to the contract address, which should always be 0 on token transactions; 6. data: encoding of the contract method together with its parameters; 7. chainId: identifier code of the Ethereum network [50]. 4. Sign the created transaction object; 5. Send the signed transaction to the Ethereum network. The implementation of the transaction process (shown in Figure 18) was not straightforward, since we found that the _eth-lightwallet_ library was no longer compatible with the latest version of _web3_, so it was necessary to reimplement the _signTransaction_ method, which signs a transaction object. Figure 17: Application Binary Interface (ABI) example of the “transfer” method. List of Transactions from an Account  
Unlike the YABW application, the CriptoSenhas application only has a list of transactions sent through the application itself. This is due to the fact that the Ethereum RPCs do not provide a specific method to obtain all the transactions. In addition, it requires that they are obtained from block to block. Although this is a possible solution, it would spend significant computing resources on the users' devices, which is not a good practice in the context of mobile devices.