Quick Guide for Smart Contracts Creation and Deployment on Ethereum Blockchain by Dr. Hedaya Mahmood Alasooly

Quick Guide for Smart Contracts Creation and Deployment on Ethereum Blockchain by Dr. Hedaya Mahmood Alasooly

Author:Dr. Hedaya Mahmood Alasooly
Language: eng
Format: epub
Publisher: BookRix


h) Sending Ether & Events

Now let's write a function that accepts Ether. To demonstrate this, I'll create an ico-like contract with a buyToken() function. This will allow an account to send ether to pay for tokens with Ether. The smart contract will be responsible for issuing the tokens, tracking the balance of the account, and also transferring the Ether funds to another wallet address.

First we'll create a mapping to track the token balances like this:

mapping(address => uint256) public balances;

Now I'll create the buyToken() function that will increment the balance like this:

function buyToken() public {

balances[msg.sender] += 1;

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.