token - Where do the ethers come from when sending ethers with .send() function in ethereum contract -




i'm learning ethereum token contract following here. i'm confused code below:

function sell(uint amount) returns (uint revenue){ if (balanceof[msg.sender] < amount ) throw;        // checks if sender has enough sell balanceof[this] += amount;                         // adds amount owner's balance balanceof[msg.sender] -= amount;                   // subtracts amount seller's balance revenue = amount * sellprice; if (!msg.sender.send(revenue)) {                   // sends ether seller: it's important     throw;                                         // last prevent recursion attacks } else {     transfer(msg.sender, this, amount);             // executes event reflecting on change     return revenue;                                 // ends function , returns } 

}

the line msg.sender.send(revenue) means send ethers seller. question is:

does ethers sent come msg.sender or token contract? think comes msg.sender. msg.sender in behalf of seller, right? makes seller sends himself ethers. may know how understand this. , how make contract send ethers user account automatically?

thanks!

i did tests figure out question. find out ethers sent destination address token contract instance address.

i confused before because didn't understand how contract instance gains ethers after being constructed. know contract instance gains ethers when account invokes method marked keyword payable of contract. when invoking happens ethers sent contract address @ meantime. in demo token code, method buy() plays role send ethers contract address.

i'm new learning ethereum contract. there still mistakes realize. please let me know if there are. appreciate that!

thanks!





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -