1

I want to create a smart contract that users can send a number to and receive an amount of ether.

function airdrop(uint val) public payable {
    require(airdrop == true);
    if (val == 0x31){
        msg.sender.transfer(1 ether);    
        airdrop = false;
    }        
}

If users send a 1 they get the ether. How can I do this?

1

You can simply check val as a uint. Your code would look as follows:

function airdrop(uint val) public payable {
        require(airdrop == true);
        if (val == 1){
            msg.sender.transfer(1 ether);    
            airdrop = false;
        }        
    }
  • 1
    and how can I send the value? I need it as hex - is it just calling the contract with data = 0x31? – Phash Sep 1 at 20:25
  • Send the value in ETH? You can simply do msg.sender.transfer(val ether); – shane Sep 1 at 20:26
  • 1
    No, i want to call this from a wallet – Phash Sep 2 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.