首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flashbots错误无法解码txn

Flashbots错误无法解码txn
EN

Ethereum用户
提问于 2023-02-21 18:23:55
回答 1查看 448关注 0票数 2

我只是试着把闪光灯和以太以及我的智能合同结合起来。在我的实现中,我使用了来自github的醚-供应商-闪光灯-捆绑指南。我所做的一切都与所描述的完全相同,但每次我的模拟都会得到错误响应:

状态: 400,原因:‘坏请求’,正文:‘{“错误”:“无法解码txs"}',

这是我的相关代码:

代码语言:javascript
复制
    const provider = ethers.getDefaultProvider('goerli');
    const wallet = ethers.Wallet.fromMnemonic("[mnemonic]");  
    const myContract = new ethers.Contract("[contract address]", myABI, provider);

    const flashbotsProvider = await FlashbotsBundleProvider.create(
        provider,
        wallet,
        'https://relay-goerli.flashbots.net/',
        'goerli'
    );

    const txn = await myContract.populateTransaction.simpleSwap(ethers.utils.parseEther(0.001), 0, path, {
        gasPrice: ethers.utils.formatUnits(await connection.getGasPrice(), "wei"),
        gasLimit: ethers.utils.hexlify(600000),
        nonce: connection.getTransactionCount(wallet.address)
    });

    const txBundle = [
        {
          signer: wallet,
          transaction: txn
        }
    ];
    
   const signedTransactions = await flashbotsProvider.signBundle(txBundle);
   const targetBlockNumber = (await connection.getBlockNumber()) + 1;
   const simulation = await flashbotsProvider.simulate(signedTransactions, targetBlockNumber);
   console.log(JSON.stringify(simulation, null, 2));

再一次,我得到的全部回应,无论我如何尝试:

代码语言:javascript
复制
{
reason: 'bad response',
code: 'SERVER_ERROR',
status: 400,
headers: {
date: 'Tue, 21 Feb 2023 18:06:49 GMT',
'content-type': 'application/json',
'content-length': '32',
connection: 'close',
'x-amzn-requestid': '4796dc12-3844-499d-8d02-8fa216abfdbf',
'x-amz-apigw-id': 'As45CHpdCYcFd1w=',
vary: 'Origin',
'x-amzn-trace-id': 'Root=1-63f50839-69ab4464245af2172e0bbef9;Sampled=0'
},
body: '{"error":"unable to decode txs"}',
requestBody: '{"method":"eth_callBundle","params":[{"txs":["0xf9012c820318850d36e6843a830927c0947d835a5d8d5ec1bba64b2dc9488062c9a242978680b8c45a5f8a5500000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d60000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9841ba0cac85fb1cb51518f2a0755d82e4ea3c18da3d186784c6b8d55bee433dd0f7852a012736aae7a6a1009f2cec370fa38a14f84029043b4753bff47b28a2fe819b3bc"],"blockNumber":"0x822fe8","stateBlockNumber":"latest"}],"id":42,"jsonrpc":"2.0"}',
requestMethod: 'POST',
url: 'https://relay-goerli.flashbots.net/'
}

我希望有人能帮我。我会很感激的。如果你对我的代码有更多的疑问,请问。

EN

回答 1

Ethereum用户

发布于 2023-03-15 04:09:47

我刚才也遇到了同样的问题。

解决方案是在bundleTransactions的每个TransactionRequest对象中添加D1

github示例在传递给TransactionRequest对象的signBundlesendBundle方法的bundleTransactions数组的每个FlashbotsBundleProvider对象中不包含链id。

出现错误的Modified github示例代码:

代码语言:javascript
复制
const bundleTransactions: Array = [
    {
      transaction: {
        //chain id was not included in the github example, but it's required
        //chainId: 5,//assuming you're testing on ethereum's goerli testnet
        to: walletExecutor.address,
        gasPrice: gasPrice,
        value: gasEstimateTotal.mul(gasPrice),
        gasLimit: 21000,
      },
      signer: walletSponsor
    },
    ...sponsoredTransactions.map((transaction, txNumber) => {
      return {
        transaction: {
          //chain id was not included in the github example, but it's required
          //chainId: 5,//assuming you're testing on ethereum's goerli testnet
          ...transaction,
          gasPrice: gasPrice,
          gasLimit: gasEstimates[txNumber],
        },
        signer: walletExecutor,
      }
    })
  ]

我还在FlashbotsBundleProvider创建方法调用中遇到了另一个错误。

https://docs.flashbots.net/flashbots-auction/searchers/advanced/goerli-testnet

上面的链接提供了帮助。我还需要将网络的名称传递给create方法以及在示例中传递的connectionInfoOrUrl

示例中的The代码:

代码语言:javascript
复制
const flashbotsProvider = await FlashbotsBundleProvider.create(
    provider, walletRelay, 'https://relay-goerli.epheph.com/'
);

实际工作的The代码:

代码语言:javascript
复制
const flashbotsProvider = await flashbots.FlashbotsBundleProvider.create(
  provider,
  authSigner,//---same as walletRelay in the example. Just a different name.
  "https://relay-goerli.flashbots.net",
  "goerli"//the netowork name missing
);

我目前正在测试我从flasbots构建的帮助类。

它应该是一个简单的Flashbots构建器类,用于执行任何类型的闪存包事务。

我将编辑这包括一个npm的链接,一旦我完成。

Here是如何使用Flashbots类的:

代码语言:javascript
复制
//Build a flasbot
FlashBot.Builder()
.addSponsorPrivateKey(process.env.SPONSOR_PK_ETH)
.addExecutorPrivateKey(process.env.EXECUTOR_PK_ETH)
.addBlockChainRpcProvider(BLOCKCHAIN_RPC_PROVIDER_TEST)
.addBundleProviderConnectionInfoOrUrl(FLASH_BOTS_RPC_URL_TEST)
.addBundleProviderNetwork(FLASH_BOTS_RPC_NETWORK_TEST)
.addBlockchainNetworkId(FLASH_BOTS_RPC_NETWORK_ID_TEST)
.build()
.then(async (flashBot) => {
    //access the sponsor and executor Wallet object
    const sponsor = flashBot.getSponsorWallet()
    const executor = flashBot.getExecutorWallet()

    console.log(`sponsor: ${sponsor.address} | executor: ${executor.address}`)
    
    //create an ERC20 transfer
    const engine = new TransferERC20(
        flashBot.getProvider(), 
        executor.address, 
        sponsor.address, 
        TOKEN_ADDRESS_TEST,
        utils.parseEther("500000")
    );
    //get the transaction
    const sponsoredTransactions = await engine.getSponsoredTransactions()

    console.log("Engine Description:", await engine.description(), sponsoredTransactions)
    
    flashBot
    .addMultipleBundleTx(sponsoredTransactions)
    .execute(authSignerPrivateKey)//If the authSigner is not passed, one will be generated and included in the promise's result
    .then((result) => {
        console.log("result:", result)
    })
    .catch(e => {
        console.log("error:", e.message)
    })
})
.catch(e => {
    console.log("error:", e.message)
})

编辑:

flasbots构建器库现在可以在npm上使用。安装with: npm安装闪存机器人-生成器

Library Github: https://github.com/feyi-tech/flashbots-builder

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/145349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档