Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to transfer etheric coins or ERC20 tokens to multiple addresses with one transaction

Shulou Source: shulou.com Published: 2022-06-01 08:09:04 10月03日 Update

This article mainly explains "how to transfer etheric coins or ERC20 tokens to multiple addresses with one transaction". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to transfer etheric coins or ERC20 tokens to multiple addresses with one transaction".

1. Summary of implementation ideas

The basic idea is to use a smart contract to pass the target address as a parameter to the intelligent contract and let the contract execute the transaction for us: since we only need to call the method of the contract once, we only need to pay the gas fee for one transaction, while the internal transaction of the intelligent contract does not need to pay the handling fee.

The whole deal process looks like this:

| |-transfer--- > address requests |-transfer--- > address 2#DApp-- multiTransfer-- > Contract-- |. |. | |-transfer--- > address N# | 2. Ethernet currency one-to-many transfer transaction |

The following is the contract implementation code for the etheric currency one-to-many transaction:

Pragma solidity ^ 0.4.18 position contract WizSendContract {/ / one-to-many ethercurrency transfer event event MultiTransfer (address indexed _ from, uint indexed _ value, address _ to, uint _ amount); / / one-to-many ethercurrency transfer method function multiTransfer (address [] _ addresses, uint [] _ amounts) payable public {uint toReturn = msg.value; for (uint I = 0; I < _ addresses.length) MultiTransfer +) {_ addresses.transfer (_ amounts [I]); toReturn = toReturn-amounts [I]; MultiTransfer (msg.sender, msg.value, _ addresses [I], _ amounts [I]);} _ safeTransfer (msg.sender, toReturn);}}

Note: this is a proof of concept / PoC code for educational purposes and should not be applied directly to the production environment.

3. Ethernet Square ERC20 tokens one-to-many transfer transaction

The following is the contract implementation code for the one-to-many transaction of ERC20 tokens in Yi Tai Fong:

Pragma solidity ^ 0.4.18 ERC20 is introduced to define import "erc20.sol"; contract WizSendContract {/ / one-to-many token transfer event event MultiERC20Transfer (address indexed _ from, uint indexed _ value, address _ to, uint _ amount, ERC20 _ token); / / one-to-many token transfer method function multiERC20Transfer (ERC20 _ token, address [] _ addresses, uint [] _ amounts) public {for (uint I = 0) I < _ addresses.length; iTunes +) {_ token.transferFrom (msg.sender, _ addresses [I], _ amount [I]); MultiERC20Transfer (msg.sender, msg.value, _ addresses [I], _ amounts [I], _ token);}

Note: this is a proof of concept / PoC code for educational purposes and should not be applied directly to the production environment.

At this point, I believe you have a deeper understanding of "how to transfer etheric coins or ERC20 tokens to multiple addresses with one transaction". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Transactions ethernet tokens contracts transfers methods addresses codes multiple intelligence events content ideas teaching concepts environment purpose this is learning payment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei Docker OPPO Reno MySQL