介绍
在不断发展的以太坊领域,矿工(现为验证者)对区块内交易的纳入具有一定程度的影响力。这种影响力可以用来获取额外的价值,通常以牺牲普通用户为代价。这种现象被称为最大可提取价值 (MEV)。Flashbots 作为一种解决方案应运而生,旨在减轻 MEV 的影响并让用户更好地控制自己的交易。
什么是 Flashbots?
使用Flashbots的好处
增强交易速度: Flashbots 交易通常比公共内存池中滞留的交易更快地获得纳入,从而加快了确认速度。
MEV 保护:通过绕过公共内存池,Flashbots 可以保护您的交易免受可能试图操纵交易以谋取私利的 MEV 机器人的攻击。
灵活性: Flashbots 允许用户指定他们愿意向区块构建者提供的最大 MEV 份额,从而确保透明度。
谁应该考虑使用 Flashbots?
虽然 Flashbots 具有诸多优势,但它主要针对特定的用户群体:
在 JavaScript 中使用 Flashbots Protect
先决条件:
一步步:
const ethers = require("ethers.js");const { FlashbotsBundleProvider,} = require("@flashbots/ethers-provider-bundle");
// Standard json rpc provider directly from ethers.js. You can use Infura, Alchemy, or your own node.const provider = new ethers.providers.JsonRpcProvider({url: ETHEREUM_RPC_URL,});// `authSigner` is an Ethereum private key that does NOT store funds and is NOT your bot's primary key.// This is an identifying key for signing payloads to establish reputation and whitelistingconst authSigner = new ethers.Wallet("0x0000000000000000000000000000000000000000000000000000000000000000");// Flashbots provider requires passing in a standard provider and an auth signerconst flashbotsProvider = await FlashbotsBundleProvider.create(provider,authSigner);
const transaction = {from: signer.address,to: signer.address,value: "0x42",gasPrice: BigNumber.from(99).mul(1e9),gasLimit: BigNumber.from(21000),};
const res = await flashbotsProvider.sendPrivateTransaction({transaction,signer,},{maxBlockNumber: (await provider.getBlockNumber()) + 5, // only allow tx to be included for the next 5 blocks},);
const waitRes = await res.wait();if (waitRes === FlashbotsTransactionResolution.TransactionIncluded) {console.log("Private transaction successfully included on-chain.");} else if (waitRes === FlashbotsTransactionResolution.TransactionDropped) {console.log("Private transaction was not included in a block and has been removed from the system.",);}
更多文档: https://docs.flashbots.net/flashbots-protect
结论
总之,Flashbots 代表了以太坊交易处理的革命性进步,提供了增强的隐私性、效率和安全性。通过绕过公共内存池并促进与矿工的直接互动,Flashbots 使用户能够以前所未有的速度和隐私性执行交易,彻底改变了我们与去中心化应用程序互动的方式。随着以太坊生态系统的不断发展,Flashbots 将在塑造区块链技术的未来方面发挥关键作用,使用户和开发人员都能在去中心化金融、数字所有权等领域开启新的可能性。
感谢阅读 Verichains!免费订阅以接收新帖子并支持我的工作。