Implement Multi Send on Ethereum by Smart Contract with solidity
Bitcoin transaction structure provides the capability of sending multiple outputs to different addresses in only one transaction. This feature can help to decrease the transaction fee by encapsulating multiple sends in only one transaction. But in Ethereum it’s not as simple as Bitcoin to send different payments to different addresses in only one transaction.
Account Types in Ethereum
In Ethereum there are two types of accounts, externally owned accounts, and internally owned accounts.
Externally owned accounts: These types of accounts are controlled by a private key that is owned by a user (like you) and can create and sign a transaction and then broadcast it to the network. It is called Externally owned because the account can be controlled by a private key that is out of the blockchain, and only the signed transaction is placed on the blockchain.
Internally owned accounts: These types of accounts are controlled by a code (smart contract) that is stored on the blockchain. In other words, each smart contract has an account, and its code controls the account. It is called an Internally owned account because the account is controlled by a code that is on the blockchain.
each account has four fields, nonce, balance, code-hash, and storage-root.
Nonce: is the counter of transactions that is broadcasted by the account.
Balance: is the balance of the account in wei ( 1 Ether = 1⁰¹⁸ wei )
Code-Hash: for externally owned accounts is the hash of an empty string, and for internally owned accounts is the hash of the code.
Storage-root: is the root node of a Merkle particial tree that encodes the content of the account.
Smart Contract
Ethereum provides a Turing-complete language and this capability enables the concept of smart-contract and dapp (decentralized application).
Anyone can deploy a smart-contract on the blockchain if she/he pays the deployment fee.
The most popular language for writing smart-contract on Ethereum is Solidity, and Remix is an online IDE for it.
the pic of Rimex
To interact with Remix you can use JavaScript VM, Injected Web3, or Web3 Provider in the section of Deploy and run Transaction. The first one runs the smart-contract locally on your browser, and the second one deploys the smart-contract on the blockchain using a connected wallet.
The concept of smart-contract enables many use-cases on the blockchain, like ICO (Initial Coin Offering), DAO (Decentralized Autonomous Organization), and DeFi (Decentralized Finance).
With smart-contracts the result of a code would be consistent because of the massive resources spent on the consensus process, and the data stored on the blockchain would be immutable.
Now I want to deploy a smart-contract to use for multiple withdrawals to decrease the fee of sending multiple transactions.
Rimix IDE
First should go to Remix, can use this link.
The IDE is like the above picture, at the left side can see file explorer, compilers, deploy, and plugin manager sections.
To program the multi send smart-contract first create a new file from the file section, by right click on the contracts folder.
Multi Send Smart Contract
It’s the solidity code of the multi send smart contract:
Now need some amount of test Ether to deploy and test the smart contract. I prefer Rinkeby test network to deploy the smart contract.
To this purpose can get some amount of test Ether from https://faucet.rinkeby.io/ .
if you charge your ethereum account, on Meta Mask or other wallets that can be connected with Remix, then it’s time to deploy the smart-contract. first compile it.
after that need to choose Injected Web3 as the deploy environment.
By clicking on Injected Web3, it automatically connect to the Meta Mask.
By clicking on Deploy, it deploys the smart-contract on the blockchain.
after deploying the smart-contract it would be accessible on blockchain.
https://rinkeby.etherscan.io/tx/0x1dc8de30c0ac46935b5bd81db5c84c4fa4e4433840f3d8b31e44cb7b90e2f276
Calling Multi Send
To run (or call) the smart-contract, need to provide an array of addresses and an array of amounts for each address and provide the exact amount of sum of all this amounts in the value box, then click on Transact .
For Example by providing:
Value: 123000000000 wei
Address array: [“0xf92abF80266fD710Ec7a8A644915B458abe34160”]
Amount array: [123000000000]
(sum of the array elements of the amount array should be equal to value)
and clicking Transact got this transaction:
https://rinkeby.etherscan.io/tx/0x1428839b24c211bc997658ee35b4ca9d9a2f3368166bbce08f97a47e640718b8
(this story is edited and the smart-contract is improved, and the last picture contains the new features)
Join Coinmonks Telegram group and learn about crypto trading and investing
Also, Read
- The Best Crypto Trading Bot | Grid Trading Bots
- Crypto Copy Trading Platforms | Top 5 BlockFi Alternatives
- CoinLoan Review | Crypto.com Review | Huobi Margin Trading
- YouHodler vs CoinLoan vs Hodlnaut | Cryptohopper vs HaasBot
- Leveraged Token | Best Crypto Exchange | Paxful Review
- How to buy Bitcoin in India? | WazirX Review | BitMEX Review
- Gemini vs Coinbase | Coinbase vs Kraken | CoinJar vs CoinSpot
- Binance vs Kraken | Dollar-Cost Averaging Trading Bot
- Bitcoin exchange in India | Bitcoin Savings Account
- Binance Fees | Botcrypto Review | Hotbit Review | KuCoin Review
- My Experience with Crypto Copy Trading | Coinbase Review
- Cryptocurrency Savings Accounts | YoBit Review | Bitbns Review
- Best Bitcoin Margin Trading| Bityard Margin Trading
- Crypto Margin Trading Exchanges | Earn Bitcoin | Mudrex Invest
- BlockFi Credit Card | How to buy Bitcoin on Binance
- Top paid cryptocurrency and blockchain courses | Binance Review
- MXC Exchange Review | Pionex vs Binance | Pionex Arbitrage Bot
- How to use BitMEX in the USA? | BitMEX Review | Binance vs Bittrex