Is everyone ready for the first smart contract?
I've had several coin developers coming to me asking if I could help them create their own coin. Well, I have a better solution for them, one that benefits Krypton also. That solution is to create a side chain of KR, in essence, a token or colored coin for them. Here's the smart contract to do this:
contract MyToken {
/* Public variables of the token */
string public standard = 'Token 0.1';
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
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,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
msg.sender.send(msg.value); // Send back any ether sent accidentally
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
returns (bool success) {
allowance[msg.sender][_spender] = _value;
tokenRecipient spender = tokenRecipient(_spender);
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
allowance[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
/* This unnamed function is called whenever someone tries to send ether to it */
function () {
throw; // Prevents accidental sending of KR
}
}
The only difference in how KR works from ETH at this time is this:
KR contracts must be deployed from the command line.
There are Krypton notes in the document, Beginning Solidity Development, that explain how to compile and deploy contracts.
https://docs.google.com/document/d/1Xn1frVpyjBJI0KCJt94Nok_meQY0o3Xd6yZUxSE-gUM/edit#heading=h.p65zjxf2oav4
Here is the original documentation from ETH: https://www.ethereum.org/token
###
All of the above is in this Google document:
https://docs.google.com/document/d/1_P9YRcxAXopotvlY_ruYueyNsvpGOKYpu-U_EFp445U/edit?usp=sharing
Any developers now wanting to create their own coin can easily do this right now. If you need assistance, shinohai is available to help you for a small fee. He can be reached on irc freenode #Kryptoncoin. You can also ping shinohai through Krypton's slack. http://slack.krypton.rocks .
Enjoy, people!
And don't forget to re-tweet about it! Please.
https://twitter.com/covertress/status/762984989084581888
Good morning, Krypton!
We already have a first coin project that is being added to the KR blockchain (that we know of.)
No one is required to inform me when they want to use this smart contract to create their own coin but, it would be nice if you did and introduced your project here.
In addition, dear developers, if you do create your own KR-flavored coin, I will offer you a subdomain name of Krypton.Rocks in order to help promote your project. Example: www.YourCoin.Krypton.Rocks
If you're interested, please drop by Krypton's slack and post about your project in the #development room. We in the Krypton Community would all be interested to learn more about your project and/or offer advice on coin creation.
Hope to see you in slack!
http://slack.krypton.rocks