Web3js
我如何通過支付一筆交易費用在一筆交易中將乙太幣發送到多個地址?
我如何通過支付一筆交易費用在一筆交易中將乙太幣發送到多個地址。就像我想一次性發布多筆交易一樣,我只能產生一筆交易費用。
我如何在一次交易中將乙太幣發送到多個地址以便一次性支付交易費用?
通過在合約建構子中聚合多個傳輸,然後部署該合約。
例如:
pragma solidity 0.6.12; contract Payer { constructor(address payable[] memory clients, uint256[] memory amounts) public payable { uint256 length = clients.length; require(length == amounts.length); // transfer the required amount of ether to each one of the clients for (uint256 i = 0; i < length; i++) clients[i].transfer(amounts[i]); // in case you deployed the contract with more ether than required, // transfer the remaining ether back to yourself msg.sender.transfer(address(this).balance); } }
簡單的方法:https ://cointool.app
更難的方法:
function multisendToken(address token, address[] _contributors, uint256[] _balances) public hasFee payable { uint256 total = 0; require(_contributors.length <= arrayLimit()); ERC20 erc20token = ERC20(token); uint8 i = 0; for (i; i < _contributors.length; i++) { erc20token.transferFrom(msg.sender, _contributors[i], _balances[i]); total += _balances[i]; } setTxCount(msg.sender, txCount(msg.sender).add(1)); Multisended(total, token);
}