Selector Setup
contract.c
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`
const uint32_t BOILERPLATE_SELECTORS[NUM_SELECTORS] = {
SWAP_EXACT_ETH_FOR_TOKENS_SELECTOR,
BOILERPLATE_DUMMY_SELECTOR_2,
};
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.
#define NUM_SELECTORS 2
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 {
SWAP_EXACT_ETH_FOR_TOKENS,
BOILERPLATE_DUMMY_2,
} selector_t;
handlers
Now we have to implement a handler for each case condition as described in the reference flow. They must all have a corresponding handle_*.c
located in src/
.