Skip to Content
LearnMEV Plugins

How to Build and Run MEV Plugins on Sei

Introduction

Sei’s MEV system is designed to make value extraction programmable, auditable, and operationally transparent. This guide provides a step-by-step walkthrough for experienced developers and node operators who want to implement, register, and operate MEV plugins on Sei. The approach here mirrors the technical rigor and visual clarity of Sei’s core protocol explainers.

Prerequisites

Before you begin, ensure you have:

MEV Plugin Interface

A Sei MEV plugin is a Go module that implements the following interface:

// MEVPlugin defines the required methods for a plugin. type MEVPlugin interface { Init(config PluginConfig) error OnBundleSubmission(bundle MEVBundle) (BundleResult, error) OnBlockProposal(ctx BlockContext, txs []Tx) ([]Tx, error) Shutdown() error }
  • Init: Called at plugin startup for initialization and configuration.
  • OnBundleSubmission: Handles incoming MEV bundles. Use this for validation, filtering, or other custom logic.
  • OnBlockProposal: Allows transaction reordering, filtering, or injection during block proposal.
  • Shutdown: Cleanup logic on node shutdown.

Example: Minimal Plugin Implementation

Below is a minimal example of a plugin that accepts all bundles and does not reorder transactions. You can extend this structure to implement custom logic as needed.

package mymevplugin import "github.com/sei-protocol/sei-chain/x/mev" type MyPlugin struct{} func (p *MyPlugin) Init(config mev.PluginConfig) error { // Initialization logic return nil } func (p *MyPlugin) OnBundleSubmission(bundle mev.MEVBundle) (mev.BundleResult, error) { // Accept all bundles (example) return mev.BundleResult{Accepted: true}, nil } func (p *MyPlugin) OnBlockProposal(ctx mev.BlockContext, txs []mev.Tx) ([]mev.Tx, error) { // No reordering (pass-through) return txs, nil } func (p *MyPlugin) Shutdown() error { // Cleanup logic return nil }

Plugin Registration and Deployment

To register and deploy your MEV plugin:

  1. Place your plugin code in the x/mev/plugins/ directory of the Sei node source.
  2. Register the plugin in the node configuration file or via a CLI flag.
  3. Rebuild the node binary to include your plugin.
  4. Restart your node to load the new plugin.

After these steps, your plugin will be loaded and invoked as part of block production.

Submitting MEV Bundles

You can submit MEV bundles to the node using the /mev/submitBundle RPC endpoint. For example:

{ "bundle": [{ "tx": "0xabc123...", "metadata": { "searcher": "alice" } }, { "tx": "0xdef456..." }] }

POST this JSON to the node’s /mev/submitBundle endpoint. The plugin’s OnBundleSubmission method will process the bundle. To query plugin status, use the /mev/pluginStatus endpoint.

  • - Log plugin activity and errors for operational visibility.
  • - Track relevant metrics, such as bundle acceptance rate and processing time.
  • - Use standard monitoring tools to observe node and plugin health.
  • - Test plugins on a staging node before deploying to production.

Security Considerations

⚠️
  • - Only run plugins that have been reviewed and audited.
  • - Restrict access to MEV RPC endpoints by using IP allowlists or API keys.
  • - Log and rate-limit bundle submissions to prevent abuse.
  • - Review plugin code for panics, resource leaks, and unsafe operations.

Troubleshooting

If a plugin fails to load, verify registration and compatibility with the node version. Node crashes may indicate panics or resource exhaustion in plugin code. Rejected bundles may be due to invalid payloads or plugin logic errors. Use profiling tools to diagnose performance issues.

Last updated on