Introducing FunctionX (FX) — Our First Ledger Nano Application

Malcolm
Function X
Published in
9 min readDec 5, 2022

An introduction to FunctionX (FX) and how to use it.

A Ledger Device is a hardware wallet that stores private keys to your cryptocurrencies in an offline or “cold” storage. Even if we make a transaction from the hardware wallet, the hardware wallet is used in an offline environment and the mechanism to sign a transaction and broadcast it back to the blockchain network ensures that our private keys are always protected from the risk of any unauthorized access through the internet.

The f(x)Core blockchain is built on top of the Cosmos SDK and Tendermint protocol. In order to increase compatibility with the Ethereum ecosystem, Ethereum signatures in the f(x)Core and MarginX chains have been introduced since f(x)Core’s EVM upgrade. This EVM integration allows decentralized exchanges (DEXes), liquidity protocols, auto-compounders and other dApps to be deployed on the Function X network. One of the outcomes of the EVM upgrade is the generation of a new type of account that has both fx and 0x wallet types linked; or in other words, the generation of accounts that can support both coin types 118 (ATOM) and 60 (ETH).

At present, as a result of the EVM upgrade, it is not possible for f(x)Core users who are using Ethereum private keys to sign transactions with the Ledger device. To meet this challenge, our development team at Function X have forked and improved the Cosmos Ledger app, and the new Ledger app that we will be launching will allow f(x)Core users to sign transactions on f(x)Core and MarginX chains, and eventually Pundi X chains, with their Ledger devices.

Enter FunctionX (FX).

FunctionX (FX)

FunctionX (FX) is our first Ledger Nano app and it is an app that will run on Ledger Nano devices. The app will be supporting the coin: FX, which is the native utility token of the Function X ecosystem. Users can use the FunctionX app to sign transactions for f(x)Core, MarginX, and Pundi X chains on their Ledger devices.

Note: FunctionX only supports f(x)Core, MarginX and Pundi X chains. Coin types ATOM and ETH cannot be used, which means that other Cosmos chains and Ethereum chains are not supported.

At present, the app can only be installed locally through Function X’s Github repository and a series of CLI command (more below). When the app gets listed on the Ledger app catalog, the app can easily be downloaded through Ledger Live. This article will be updated with a guide on how to install FunctionX through the Ledger app catalog when FunctionX is approved by the team at Ledger.

Requirements

Before installing, make sure that:

  1. Your Ledger Nano device has been initialized
  2. The latest firmware for the device has been installed
  3. Ledger Live is ready to be used
  4. Your Ledger Nano device is connected to your computer or laptop
  5. If installing locally, ensure Docker is running and pip3 is installed, and run the installation on a bash shell

Local Installation method (Linux):

The following local installation steps will be carried out on the Ledger Nano S Plus. For Ledger Nano S and Ledger Nano X, please refer to the appropriate commands as described below.

  1. Pull the code from Github and switch to the “fx” branch of the repository
git clone https://github.com/FunctionX/ledger-cosmos.git
git switch fx

2. Pull the dependent modules

git submodule update --init --recursive
make deps

3. Ensure Docker is running, and build the app

# For Nano S:
make buildS
# For Nano S Pus:
make buildS2
#For Nano X:
make buildX

4. Install the app to the Ledger device. The device must be connected at this point. And a confirmation on the Ledger device will be required

# For Nano S:
make load
# For Nano S Plus:
make loadS2
# For Nano X:
make loadX
A confirmation on the Ledger device will be triggered

5. Close Ledger Live on your computer

6. Open the FunctionX app on the device

FunctionX is now ready to be used on your Ledger Nano device.

Ledger Live installation method (Ledger app catalog):

[To be updated after approval from Ledger]

How the use of Hardware wallets enhances security and user protection

The use of hardware saves us from the anxiety of exposing our funds to cryptocurrency hacks and theft by doing something simple — they keep our private keys offline.

As mentioned in the earlier in the article, Ledger hardware wallet is a device that stores private keys to your cryptocurrencies in an offline or “cold” storage — away from the internet. And even if a transaction is made from the hardware wallet, the hardware wallet signs the transaction in an offline environment. And this process helps to keep the user’s private keys away from any internet exposure at all times. For more information on Ledger, please visit this link.

All hardware wallets are non-custodial wallets, i.e. the user is the only one who has access to his or her private keys and funds. Thus when an individual uses a hardware wallet, the individual will have the private key associated with their cryptocurrency. If you’re reading this and you take crypto seriously, and you understand the (new) risks to such assets, you will understand that this type of storage is the only truly safe option.

There are many types of hardware wallets at present, but among them, the Ledger Nano series is by far the most secure hardware wallet. Ledger provides a pretty comprehensive article on why you should consider using their hardware wallet. In addition to giving the user complete control over their funds and keeping their keys offline, the hardware wallet protects a user’s keys with a higher level chip called Secure Element (SE). SE is a component that is used in a variety of security environments such as credit cards, passports, payment systems, and crypto hardware wallets; and it is known for providing the highest level of security for any system that manages sensitive data.

This means that, besides keeping your private keys offline (and away from hackers), the Ledger Nano device itself is also completely immune to external threats — all thanks to the host of state-of-the-art components inside.

Flowchart

How to Use FunctionX

Currently, the FunctionX app only supports transaction signing on f(x)Core, MarginX and Pundi X chains. Users would also need to have a copy of our fxdexd binaries to use the CLI tool to interact with the FunctionX app. Now that FunctionX is installed, here are some examples of how it can be used with Ledger devices.

1. Import of Key

Check the address of the key imported by the specified derivation path. If an account is imported using the same seed phrase of the Ledger device, you can check to see if the addresses match. Use the fxdexd CLI tool to import the key, and confirm in the FunctionX app.

# ledgerKey is the name of the key, which can be chose arbitrarily
# --ledger is the flag to interact with the Ledger device
# --acount is the flag for the account number in the BIP44 derivation path,
# and the value range is: 0 - 100 (Limitation of the Cosmos app)
fxdexd keys add ledgerKey --ledger --keyring-backend test --algo eth_secp256k1 --account 0
Entering the above command will trigger a transaction review on the Ledger device.
Press the right button on the Ledger device to review the transaction details, until you see “APPROVE” then press both buttons.
The CLI tool will return the address derived from the seed phrase of the Ledger device.
The address on f(x)Wallet matches that of the Ledger device.

2. Transaction Signature using MarginX

Because all assets on MarginX are cross-chained from f(x)Core, users will need to first receive test tokens from the faucet and then cross-chain the assets through the MarginX cross-chain bridge.

Get the test tokens (f(x)Core-EVM USDT & f(x)Core FX) here.

Import the Ledger seed phrase into the f(x)Wallet app. You should see that your account has USDT on the f(x)Core chain.

When importing an account with the Ledger device’s seed phrase, select “Advanced Options” and choose “m/44'/60'/i’/0/0”. Note that if you choose another derivation path, you will not get the same address.
Account assets on f(x)Core chain.

Open MarginX’s exchange page and link your f(x)Wallet. Click on “Connect Wallet” and scan the QR code with your f(x)Wallet. You’ll be asked to authorize the connection on f(x)Wallet.

Click on “Connect Wallet” to open the QR code.
Scan the QR code with f(x)Wallet to establish the connection.

After connecting to MarginX, on the same page, click on “Bridge”, and bridge your tokens to one of the chains of MarginX. Here we will bridge USDT tokens to MarginX’s BTC/USDT chain.

Click on “Transfer” to initiate the transaction.
A signature will be required in f(x)Wallet.
Hit the “Sign” button on f(x)Wallet to sign and approve the transaction. When the transaction is signed, a confirmation pop-up will appear on the MarginX page.

Next, check the transaction status to ensure that the transaction was successfully confirmed and executed correctly; and that the address of the sender of the transaction matches what is displayed on the Ledger device. We will execute the transfer transaction through the CLI tool, and sign the transaction on the Ledger device. Be sure to specify the node RPC at the end of the CLI command and include the appropriate chain-id.

# Transfer transaction. After confirming on the CLI, sign the transaction on the Ledger device
fxdexd tx bank send ledgerKey 0x61bd2030908d658dd5a2139D2C13Af55b9138efb 10USDT --keyring-backend test --ledger --sign-mode "amino-json" --node "https://testnet-btc-json.marginx.io:26657" --chain-id "MarginX-Testnet-BTC"
Executing the command will trigger a confirmation on the CLI. Hit: “y”, followed by the “return” (or “enter”) button to confirm the transaction.

Next, the transaction will be signed on the Ledger device. When reviewing the transaction, users will be able to review the chain ID, account, sequence, type of the transaction, amount transacted, from address, to address, transaction fees, and gas amount.

Users can press the right button on the Ledger device to review the transaction details.
This is the address associated with the device’s seed phrase. It matches the address of the sender of the transaction (see next image).
The “from_address” represents the address of the sender of the transaction.
Press both buttons on the Ledger device to approve and sign the transaction.
Once the transaction is signed on the Ledger device, the CLI tool will return the following response. Users can copy the transaction hash (txhash) and view the transaction on StarScan explorer.

Viewing the Transaction on StarScan Explorer

After signing the transaction on the Ledger device, user’s will be able to copy the transaction hash returned in the CLI and view the transaction on our blockchain explorer.

Uninstalling FunctionX

To delete the app on the Ledger device, connect the Ledger device to the computer and run the following command

# For Nano S:
make delete
# For Nano S Plus:
make deleteS2
# For Nano X:
make deleteX

Sample Test Code That Interacts With Ledger Emulator

What’s next?

If you have not heard about Function X or MarginX and would like to find out more, be sure to check us out in the links below :)

We will be working to get FunctionX listed on the Ledger Live app catalog so that f(x)Core users can install the app easily through Ledger Live. Once FunctionX is approved by Ledger, we will update this article on how to install our app through Ledger Live, so stay tuned!

Support

Function X: https://functionx.io/

MarginX: https://marginx.io/

StarScan Explorer: https://starscan.io/

StarScan Forum: https://forum.starscan.io/

Function X on Medium: https://medium.com/functionx

Function X Foundation on Medium: https://medium.com/@functionx_io

Ledger: https://www.ledger.com/

Resources

FunctionX (FX) application Github repository:

--

--