I am creating a test app that reward users that complete a survey with an ERC20 token. I already have the ERC20 smart contract with a token supply of 5000000 token and the survey app in react and javascript. I want to link the two together so when a user click on submit, they receive 10 token from the initial wallet address.
It seems like your target is to reward some token, but for your code just like above, it means you want to reward ETH. I think it should be token.transfer(to, amount)
Up to you, I just mean, you should use token.transfer(to, amount) to transfer token, the code you wrote above address(Reward.author).transfer(msg.value); is transferring ETH.
Okay, maybe I misled you. It should be YOUR_TOKEN.transfer(RECIPIENT_ADDRESS, TRANSFER_AMOUNT), for example, Alice should get 10 DAI, so it should be DAI_CONTRACT.transfer(ALICE_ADDRESS, 10e18)
Hello, I tried what you did but didn't manage to do it. I think the easir thing to achieve what i want is to implement an airdrop function or contract.
function getAirdrop() public {
token.transfer(msg.sender, 100000000000000000000); //18 decimals token
}
Do i need it to put in a different file or can i put it in the same contract as the token creation?
So for your function getAirdrop(), you mean you want the users to call this function with Ether, just like uses 1 Ether to get 1 airdrop token, right?
I think it looks like ok, just ensure your contract have enough token to transfer out, and when you call this function with Ether, I think it should be YOUR_CONTRACT.methods.getAirdrop(AN_ADDRESS, {value:ETHER_AMOUNT}) (I use web3.js, if you use other ways, maybe there will be some differences)