Skip to content

handle_query_contract_ui()

Handle explanation

The Ethereum application will call this handle for each screen to display if a custom UI was requested.

The plugin needs to perform the following actions:

  • Write the screen title for the current screen index
  • Write the screen content for the current screen index

An example is already done in the boilerplate plugin. Adapt and expand it for your use case.

Fields descriptions

typedef struct ethQueryContractUI_s {
    // DEPRECATED, will be removed soon. Do not use.
    ethPluginSharedRW_t *pluginSharedRW;

    // INPUT. Transaction data available to the plugin. READ-ONLY.
    ethPluginSharedRO_t *pluginSharedRO;

    // INPUT. ERC20 token information as requested by tokenLookup1 in
    // handle_finalize. NULL if not found.
    union extraInfo_t *item1;
    // INPUT. Same as item1 but for tokenLookup2.
    union extraInfo_t *item2;

    // INPUT. String that holds the network ticker
    char network_ticker[MAX_TICKER_LEN];

    // RW INPUT. Contains the semi-persistent RAM space that can be used by the
    // plugin in each handle call.
    uint8_t *pluginContext;

    // INPUT. Current screen to display.
    uint8_t screenIndex;

    // OUTPUT. Pointer to the first line of the screen, to be filled by the
    // plugin
    char *title;
    // INPUT. Maximum possible title length
    size_t titleLength;

    // OUTPUT. Pointer to the second line of the screen, to be filled by the
    // plugin
    char *msg;
    // INPUT. Maximum possible msg length
    size_t msgLength;

    // OUTPUT. Used by the plugin to inform the Ethereum application of the
    // result of this handle The following return codes are expected, any other
    // will abort the signing process:
    // - ETH_PLUGIN_RESULT_OK
    eth_plugin_result_t result;

} ethQueryContractUI_t;

Provided token structure

This is the structure given by the Ethereum application to the plugin.

// NFT

#define COLLECTION_NAME_MAX_LEN 70

typedef struct nftInfo_t {
    uint8_t contractAddress[ADDRESS_LENGTH];  // must be first item
    char collectionName[COLLECTION_NAME_MAX_LEN + 1];
} nftInfo_t;

// TOKENS

#define MAX_TICKER_LEN 11  // 10 characters + '\0'

typedef struct tokenDefinition_t {
    uint8_t address[ADDRESS_LENGTH];  // must be first item
    char ticker[MAX_TICKER_LEN];
    uint8_t decimals;
} tokenDefinition_t;

// UNION

typedef union extraInfo_t {
    tokenDefinition_t token;
// Would have used HAVE_NFT_SUPPORT but it is only declared for the Ethereum app
// and not plugins
#ifndef TARGET_NANOS
    nftInfo_t nft;
#endif
} extraInfo_t;