介紹
在不斷發展的以太坊領域,礦工(現為驗證者)對區塊內交易的納入具有一定程度的影響力。這種影響力可以用來獲取額外的價值,通常以犧牲普通用戶為代價。這種現象被稱為最大可提取價值 (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!免費訂閱以接收新帖子並支持我的工作。