I want to write a function let user deposit 1 eth to a specific address for registering purpose.
pragma solidity ^0.5.0;
contract Election {
mapping(uint => UserRequest) public userRequest;
// chairman account, let airline deposit to become a member
address payable chairman;
// Constructor
constructor () public payable {
chairman = msg.sender;
}
function register() public payable{
chairman.transfer(1 ether);
}
}
While I test the register()
on the remix, the following error threw out.
transact to Election.register errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information.
Some solution I found said I need to deploy it with a certain value, but what does that mean?
register
function (i.e., how do you call it and whatmsg.value
do you pass to it)? – goodvibration Apr 28 '19 at 16:39register
) to your own account (i.e., the account which you have deployed your contract with). But you do this fund-transferring via the contract, i.e., the user sends to the contract and the contract sends to your account. No problem with this method so far, only, you are assuming that there is always at least 1 ether left in the contract, while this fact depends on how much the users have sent each time one of them has called theregister
function. – goodvibration Apr 28 '19 at 16:41account A
, switch the account toaccount B
, and then clickregister
on the remix IDE – Coda Chang Apr 28 '19 at 16:56