I’m creating a function that will allow users to claim an Air Drop if they held another token in the past.
I’ve gathered up the list of the addresses and the amount of token they will get when they claim the airdrop.
The untested code is below, and I know of some problems it will have which I can deal with later on during testing.
// Air Drop Functions
function airDropClaim() public {
address claimer = _msgSender();
uint256 amountToGiveClaimer = airDropTokensLeftToClaim[claimer];
airDropTokensLeftToClaim[claimer] -= amountToGiveClaimer; // reduces the amount left to claim
approveInternal(ownerOfToken, claimer, amountToGiveClaimer); // approves amount to claim from owner address
transferFrom(ownerOfToken, claimer, amountToGiveClaimer); // transfers the airdrop amount from the owner address to the claimer
approveInternal(ownerOfToken, claimer, 0); // sets the approved amount back to zero
emit AirDropClaimed(claimer, amountToGiveClaimer);
}
The real problem is that I have 2000 Addresses to air drop to.
I can’t store them all into a Mapping during the initialization of the contract because the contract size would be too big. I’ve already tried.
Can I store the list of addresses and their amounts off chain somewhere and then call the off chain data?
Should I create a separate contract that would hold some addresses, then call them from my own contract somehow?
Any advice on how to accomplish this would be welcome. The main goal is to have a function the user can use to claim their tokens by spending their own gas to claim.
So my approach ended up being that I had to make a function to assign these addresses.
I don’t think there is any other way to off chain it, I have to pay gas at some point in order to have addresses their proper airdrop amount in their mapping.
I used an onlyOwner function below which I called after deployment.
function initializeAirDropAddressesAndAmounts(address[] memory addressesToAirDrop, uint256[] memory amountsToAirDrop) external onlyOwner() {
for(uint i = 0; i < addressesToAirDrop.length; i++){
airDropTokensTotal[addressesToAirDrop[i]] = amountsToAirDrop[i];
}
}
If anyone has a better approach let me know. This doesn’t cost too much gas for 2000 addresses, about $50 in ETH, and $10 in BNB.
I’ll check on 1inch and see if they have a guide.
I tried to understand MerkleTree, but I was having trouble grasping it. Where do the addresses come from when using a MerkleTree? I can read the code, but I feel like I’m missing something.
This is where I was reading the code for it. It looks like trustlines did this too.
If you have a tutorial or a guide on it I’ll read up on it.
We recently updated the docs with instructions of how to generate a merkle tree and corresponding merkle proofs. It’s not showing in the site yet but here it is:
Using the merkletreejs library you should be able to create a merkle tree whose leaves are the addresses that will receive tokens. You can then publish your contract with the merkle root and allow anyone to present a merkle proof to mint tokens corresponding to a leaf.
You should give users a way to obtain these merkle proofs off chain. Either posting the list of merkle proofs, posting the set of leaves, creating a website where people can calculate the merkle proof for an account, etc. The best UX would be to create a site with a “Claim” button that then sends the appropriate merkle proof in a transaction from the browser.
Let me know if you need more details to be able to build this.