Issue your own digital currency in an Ethereum wallet

The Ethereum wallet has its own contract development function, which should be the easiest way to develop smart contracts.

However, after starting the Ethereum wallet for the first time, the blocks of the test network need to be synchronized, which is time-consuming. Although the Ethereum wallet lists 3 testnets other than the mainnet, only Rinkeby works (maybe I didn't find the correct way to start the Ropsten and Solo networks).

The Rinkeby test network needs to obtain test coins first. The website connection to obtain test coins is:  https://faucet.rinkeby.io/

The way to get test coins is: send your address to an article on Google+ or facebook (need to overturn the wall), then enter the address of the article into the above URL, and then select the test coin amount, the system will automatically give it away .

After getting the test coins, you can start issuing your own digital currency. Digital currency on Ethereum is also a smart contract. Refer to the official documentation:

https://www.ethereum.org/token#the-code

Because the compiler has been updated, the smart contract code in the official document cannot be compiled normally. The following is what I can compile after modification (today is 2018.1.12, and it may not compile after the compiler is upgraded):


pragma solidity ^ 0.4.17;

contract MyToken {
    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;
    
    string public name;
	string public symbol;
	uint8 public decimals;
    
    event Transfer(address indexed from, address indexed to, uint256 value);
        
    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyToken(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits) public {
        balanceOf[msg.sender] = initialSupply;              // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
        decimals = decimalUnits;                            // Amount of decimals for display purposes
    }
        
    function transfer(address _to, uint256 _value) public {
        /* Check if sender has balance and for overflows */
        require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]);

        /* Add and subtract new balances */
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        
        /* Notify anyone listening that this transfer took place */
        Transfer(msg.sender, _to, _value);        
    }
}
    




Pay attention to the difference between return and throw in the official documentation:

To stop a contract execution mid execution you can either return or throw The former will cost less gas but it can be more headache as any changes you did to the contract so far will be kept. In the other hand, 'throw' will cancel all contract execution, revert any changes that transaction could have made and the sender will lose all ether he sent for gas. But since the Wallet can detect that a contract will throw, it always shows an alert, therefore preventing any ether to be spent at all.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325369741&siteId=291194637