简体   繁体   English

一笔交易中的多次转账?

[英]Multiple transfers within one transaction?

I am writing a program in Python using the web3 library, which needs to make several translations in a single transaction.我正在使用 web3 库在 Python 中编写一个程序,该程序需要在单个事务中进行多次翻译。 Here is an example. 是一个例子。 But I didn't find anything about it in the documentation.但是我在文档中没有找到任何关于它的信息。 Some examples do several transactions through a loop, but it doesn't suit me at all.一些示例通过循环执行多个事务,但它根本不适合我。

You have only two ways for this.你只有两种方法。

  1. You need build your own contract, that do all this transactions by one contract call.您需要建立自己的合约,通过一个合约调用来完成所有这些交易。
  2. You need use multicall -- this is special contract, exists at every network.你需要使用多重调用——这是一种特殊的合约,存在于每个网络中。 You send you transaction to multicall contract and run all by one call.您将交易发送到多重调用合约并通过一次调用全部运行。

Creating a smart contract is the only way to do it.创建智能合约是唯一的方法。

something like this:像这样的东西:

function multiSwap(uint256 deadline, uint256 amountOutMinUniswap) external payable {

    uint256 amountOutMinBancor = 1;
    uint256 amountOutMinSushiSwap = 1;

    _tradeOnBancor(msg.value, amountOutMinBancor);
    _tradeOnSushi(IERC20(BNT).balanceOf(address(this)), amountOutMinSushiSwap, deadline);
    _tradeOnUniswap(IERC20(INJ).balanceOf(address(this)), amountOutMinUniswap, deadline);

}

Check out a great article by Markus Waas - Making multiple swaps查看 Markus Waas 的一篇精彩文章 - 进行多次交换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM