0

I have a contract deployed to the Rinkeby testnet. It includes the following function:

function deposit(uint amount) payable public {
    require(msg.value == amount);
}

If I try to send ETH to this contract by calling this deposit() function with an amount that does not satisfy the condition in require, it should fail -- and it does, in Rinkeby.

But if I switch my account to Mainnet and try calling the same function(via RemixIDE), the transaction completes and my ETH actually gets sent.

Why is this happening? Is it due to the fact that my contract was not deployed to Mainnet, and therefore a tx from Mainnet is no different than sending ETH to a random address?

0

Yes.

If I try to send ETH to this contract

Given the context, I think you mean Rinkeby ETH.

by calling this deposit() function with an amount that does not satisfy the condition in require

The contract runs on Rinkeby. It doesn't like the request so it throws an exception, as designed.

But if I switch my account to Mainnet and try calling the same function(via RemixIDE), the transaction completes and my ETH actually gets sent.

There is, presumably, no code on mainnet at this contract's Rinkeby address. You're sending ETH to the address with data that specifies the function signature (deposit()) but the data is irrelevant because there is no contract to protest.

You'll be able to verify that your funds are sitting at the expected address where you sent them. They're marooned until one of two things happens. Both are unlikely.

a) Someone generates a signing key for that address

b) Someone deploys a contract at that address with the ability to spend the balance.

In case this seems strange, consider that wallets can generate addresses with public and private keys. A user can safely keep the existence of the private key to themselves and they can instruct others to send funds to their address. The existence of a private key isn't relevant until it's time to spend the funds.

Hope it helps.

1
  • Thank you @Rob Hitchens B9lab! Your answer clarified it. I do mean real ETH, not Rinkeby ETH. I wanted to see if real ETH sent to my contract on Rinkeby would be appropriately rejected, but was confused when the tx went through. The answer, as you said, is that sending to the contract's address on Mainnet just results in the funds being marooned at that address, because there's likely nothing there (since contract is only on Rinkeby)
    – jwu
    Oct 21 '18 at 19:42

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.