What you can code
Selector Setup

Selector Setup


Let’s go to the first EDIT THIS comment in app-plugin-boilerplate/src/contract.c. In this file you can list all the selectors for each contract. In this example we have two selectors but we focus only on the first one.

The first selector (or methodID) to support is SwapExactEthForToken from Uniswap V2. You can find it using Etherscan, and you can also compose it using the ABI (Application Binary Interface).

By looking at recent transactions on Uniswap (opens in a new tab), we find a transaction with the "SwapExactEthForToken" method. Here is an example (opens in a new tab). Scroll down and click on "Click to see more", to read:


The header line shows Method ID to be 0x7ff36ab5.
This is going to be the 4 bytes of SWAP_EXACT_ETH_FOR_TOKENS_SELECTOR:

static const uint32_t SWAP_EXACT_ETH_FOR_TOKENS_SELECTOR = 0x7ff36ab5;

Just a few lines below, the selectors are grouped in an array, in which there is SWAP_EXACT_ETH_FOR_TOKENS_SELECTOR.

You can also change the name of BOILERPLATE_SELECTORS throughout the project code.

// Array of all the different boilerplate selectors. 
// Make sure this follows the same order as the
// enum defined in `boilerplate_plugin.h`


Let's have a look at app-plugin-boilerplate/src/boilerplate_plugin.h mentioned in the code comments.

Start by checking the value of NUM_SELECTORS. Indeed, for the moment we only have two selectors.


Here PLUGIN_NAME is Boilerplate. Your plugin must be named appropriately here, and changed throughout the code

#define PLUGIN_NAME "Boilerplate"

Now let's look for the selectors mentioned in the comments. Since it is an enum let's change it in our selector:

typedef enum {
} selector_t;


Now we have to implement a handler for each case condition. They must all have a corresponding handle_*.c located in src/.

Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Nano S, Ledger Vault, Bolos are registered trademarks of Ledger SAS