737 336-5118 info@vironit.com

How to Develop a Blockchain Wallet App

12.03.2018 Nikita K.,Daria Mickiewicz
1 Comment
How to Develop a Blockchain Wallet App

Blockchain has brought a financial revolution to the world of digital payments. In 2017, Hackspace Capital, a venture fund, launched its own ICO,  and it had an idea to create the Hackspace Capital Mobile Application to make communication between HAC members and its platform more convenient and safe.

Hackspace Capital entrusted us with developing a cryptocurrency wallet in Ethereum blockchain to manage HAC tokens.

 

What does the Hackspace Application do?

The Hackspace cryptocurrency wallet in Ethereum blockchain is an iOS native application for managing HAC tokens. This is the best way to be part of HAC Token Sale Sessions and to manage HAC tokens safely and securely.

The app contains the following features:

  • Balance and transaction history
  • Exchange rates of HAC and ETH relative to BTC and USD
  • A QR code to receive incoming transactions
  • Ability to send tokens to another address either manually or through a QR scanning operation.
how it work

1.Login with pincode; 2. Main screen; 3. Receive screen; 4.- 6. Registration and adding pincode; 7. Send screen

 

Cryptocurrency Wallet Architecture in a Nutshell

This section assumes a basic understanding of Ethereum blockchain wallet architecture. If you are starting from scratch and don’t know what Ethereum is, how it works, or what an ICO is, you will be best served reading the following articles first:

If you already know about Ethereum, we recommend you follow along.

First, let’s look at the following diagram because it illustrates a general architecture of a cryptocurrency wallet in an Ethereum blockchain. The creation of the wallet includes the generation of 12-word mnemonic and derivation private key and address from it. A four-digit code is used for quick access to the account.

architecture

A general architecture of a cryptocurrency wallet

To implement this challenge, we used the following technologies:

  • Swift
  • RxSwift
  • Realm
  • Blockchain

 

Registration and login

To register, we generated a mnemonic code, which is better for human interaction than raw binary or hexadecimal representations of a wallet seed. The sentence can be written on paper or spoken over the telephone.

To generate a 12-word mnemonic we used BIP39, which describes the implementation of a mnemonic code or mnemonic sentence to generate deterministic wallets. We also used BIP32, which allows us to create Ethereum accounts, namely, private and public keys and addresses. For quick access to the account, we utilized a four-digit code.

 

NOTE: Instead of BIP39, you can use iOS technologies. This reduces the JavaScript code and, therefore, increases your application speed.

 

Code Example

[code language="javascript"]
// Returns randomly generated mnemonic

window.generateMnemonic = function() {

return bip39.generateMnemonic();

}

// Checks if mnemonic valid, if yes - creates wallet with specified index (default = "0")

window.createWallet = function(mnemonic, index) {

if (!bip39.validateMnemonic(mnemonic)) {

return;

}

 

if (typeof index === 'undefined') {

index = "0";

}

var seed = bip39.mnemonicToSeed(mnemonic);

var hdWallet = hdKey.fromMasterSeed(seed);

var wallet_hdpath = "m/44'/60'/0'/0/";

 

var wallet = hdWallet.derivePath(wallet_hdpath + index).getWallet();

return wallet;

}
[/code]

 

Main screen

The main screen allows users to check their balance, transaction list, and the exchange rates of HAC and ETH relative to BTC and USD.

To create a transaction list and get the Ethereum balance, we used the Etherscan API, which supports both GET/POST requests and a rate limit of 5 requests/sec.

To get information about our main account balance and tokens, we used Ethplorer API.

The exchange rates of HAC and ETH relative to BTC and USD are carried out using HitBTC API, which is extremely stable and provides an easy back office integration. It is compatible with HFT set-ups and algorithmic trading systems.

 

Code Example

[code language="javascript"]
// Returns address from account generated from mnemonic

window.getAddress = function(mnemonic, index) {

var wallet = createWallet(mnemonic, index);

return wallet.getChecksumAddressString();

}
[/code]

 

Transaction acceptance

To receive incoming transactions, a QR code is created. Share the receive address or the QR code with the person sending the digital currency and receive ETH in your Ethereum wallet.

 

Creating and sending a transaction

We created contracts on Ethereum using JavaScript API web3.js. Under the hood, it communicates to a local node via RPC calls. To work without a local node, we used the Infura service, which provides Ethereum clients running in the cloud, so users don’t have to run one yourself to work with Ethereum.

At this point, we have to create an Infura account and receive tokens to use in the web3js constructor.

NOTE: At this stage you must specify const tokenAddress and const contractAbi.

 

Code Example

[code language="javascript"]
// Sends token transaction from address getted from mnemonic to specified address

window.sendToken = function(mnemonic, amount, toAddress, gasPriceGwei, gasLimit) {

// initialization (provide our Infura node with token)

var web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/INFURA_TOKEN_HERE"));

// current wallet

var wallet = createWallet(mnemonic);

// address

var fromAddress = add0x(wallet.getAddress().toString("hex"));

 

// private key

var privateKey = Buffer.from(wallet.getPrivateKey().toString("hex"), 'hex');

 

// nonce

var transactionsCount = web3.eth.getTransactionCount(fromAddress);

var nonce = web3.toHex(transactionsCount);

 

// gas price

var gasPrice = web3.toHex(web3.toWei(gasPriceGwei, 'gwei'));

 

// gas limit

var gasLimit = web3.toHex(gasLimit);

 

// token contract

var tokenContract = web3.eth.contract(contractAbi).at(tokenAddress);

var data = tokenContract.transfer.getData(add0x(toAddress), amount, {from: add0x(fromAddress)});

 

var rawTransaction = {

from: fromAddress,

nonce: nonce,

gasPrice: gasPrice,

gasLimit: gasLimit,

to: tokenAddress,

value: "0x0",

data: data,

chainId: 0x01

}

 

const tx = new EthereumTx(rawTransaction);

tx.sign(privateKey);

const serializedTx = tx.serialize();

 

web3.eth.sendRawTransaction(add0x(serializedTx.toString('hex')), function(err, hash) {

// Asynchronous callback to iOS native environment

if (!err) {

window.webkit.messageHandlers.callback.postMessage([1, hash.toString()]);

} else {

window.webkit.messageHandlers.callback.postMessage([0, err.toString()]);

}

})

}

 

// Service function for adding "0x" to hex values

function add0x (input) {

if (typeof(input) !== 'string') {

return input;

}

else if (input.length < 2 || input.slice(0,2) !== '0x') {

return '0x' + input;

}

else {

return input;

}

}
[/code]

 

The Result

Working with Hackspace Capital helped us expand and improve our expertise in blockchain-based mobile apps. View the following video to see the results:

 

 

Client feedback

feedback

Useful links

We have created the following list of useful links during our research.

API:

  1.  Etherscan
  2. Ethplorer
    • List of Transactions – /getAddressHistory/{address}
    • Account Balance – /getAddressInfo/{address}
  3. HitBTC

 

Libraries:

  1. Generate a mnemonic
  2. Generate a wallet
  3. Web3 JavaScript app API for 0.2x.x

 

To summarize

Now you know what a cryptocurrency wallet is and why you need it. Moreover, you know how to create a wallet app.

If you are interested in developing a blockchain wallet and don’t want to spend time on programming, our services can be very useful. We have vast experience, and we will create a high-grade application and integrate a payment system you consider convenient. If you want more information, please contact us.

Please, rate my article. I did my best!

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading…

One response to “How to Develop a Blockchain Wallet App”

  1. ปั๊มไลค์ says:

    Reply

    Like!! Really appreciate you sharing this blog post.Really thank you! Keep writing.

Leave a Reply