First of all, hello. we will write a token for a project we have developed. We are creating new tokens, we want to write a simple contract on remix ethereum. We will distribute a large portion of the coin for free (airdrop), and we will divide a small portion of the remainder into pre-sales and teams. Distribute tokens to thousands of people is costly and time consuming. I have tried to solve this problem and found that by doing the same thing with this contract I have transferred 200 different adrese (see: https://etherscan.io/tx/0x71781f6300a7ab0869fc32710e5a1af43d0721e7a4d416208648e31a98d1801e) a contract. I can write the same on this remix.ethereum. assuming that we have formed a contract; can I make multiple transfers in this way? how can i do it and how can i do it? Which wallet should I use? please help me.
Solidity ERC-20 – Handling Multiple Transfers
erc-20etherremixtokenstransactions
Related Solutions
I tried calling MyToken.transferAnyERC20Token() which also uses ERC20(token).transfer(). That works fine over there, but the seemingly same call in the airdrop contract errors out.
I'm not 100% sure this is the solution, but the way you described your process hints at some confusion about where the tokens should be.
When you test manually, your externally owned account that signs the transaction needs to have tokens in order to send them. The same goes for the Airdrop. It can't send what it doesn't have.
Did you remember to transfer from the deployer/minter account to the Airdrop contract before instructing the Airdrop contract to send tokens it doesn't have?
In case it isn't clear.
- Alice deploys the contracts and Alice (usually) has 100% of the initial supply.
- Alice wants the Airdrop contract to distribute tokens, so Alice transfers sufficient tokens to the Airdrop contract.
- Alice signs a transaction to the Airdrop contract, instructing it to forward tokens in the Airdrop contract's custody to recipients.
The OpenZeppelin implementation of ERC20 which you appear to be using will throw an exception in the case that the sender (which is the Airdrop contract) has insufficient tokens to draw from for the transfer
method.
Hope it helps.
I believe @shane's answer is a bit misleading. Yes, you can add freezing functionality in your token contract, as mentioned in the comments.
If you are worried whether this gives "too much power" to the token contract owner, it's just an issue about how the freezing functionality is coded. If you add a generic possibility to freeze whatever transfers whenever the owner wants then I agree that it might not be a good idea business-wise.
However, nothing stops you from implementing the freezing functionality so that (certain) transfers can be frozen only during some time (or other criteria) and after that the freezing functionality would not work anymore and it would be useless.
So your transfer
function could have something like this:
pragma solidity ^0.4.25;
contract TokenContract {
uint256 freezingPossible = 1539060104; // decides by you
address oneFrozen = 0x123;
function transfer(address to, uint tokens) public returns (bool success) {
if (now < freezingPossible) {
require(to != oneFrozen, "The account should not be frozen");
}
// normal transfer logic
}
}
The above code actually prevents transferring tokens to the frozen account, not from it as is required, but hopefully you get the idea.
Remember to implement similar functionality also for transferFrom
.
Best Answer
As i understand, you guys want to distribute tokens to thousand of addresses in a single transaction. This code you are using is totaly fine i.e
In this way you guys can mint a tokens to multiple address, but you should not use this snippet to transfer tokens, transfer must be happen by token owner only on their own will. You can use "MetaMask" wallet to sign transaction.