Selector Setup | Developers

Selector Setup

Estimated reading time: 2 minutes


Let’s go to the first EDIT THIS comment in app-plugin-boilerplate/src/main.c. We start by implementing just a single selector because others are added later.

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, we find a transaction with the “SwapExactEthForToken” method. Here is an example. 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 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 selector mentioned in the comments. Since it is an enum let’s change it in our selector:

typedef enum {
} selector_t;


We must also change the name of BOILERPLATE_SELECTORS to match the one used in main.c.

Now let’s go back to main.c. We see that it contains a function called dispatch_plugin_calls(). We will go through each case condition in the pages below. They must all have a corresponding handle_*.c located in src/. Remember to use the reference flow to have a complete view of what is going on.

Did you find this page helpful?

How would you improve this page for developers?

Boilerplate plugin
Init contract
Getting Started
Theme Features