As described in a previous article I spent a day taking a deep dive into ethereum. This is the follow up post that will provide the details and outcome of the day.
Josh Mather wrote an excellent article last year explaining how to get ethereum up and running: https://developer.vantiv.com/community/news-and-communications/blog/2016/08/05/explorations-in-ether.... My main deviation from Josh's info is that I installed Mist and leveraged it as a learning tool. In addition I installed Mist on Windows 10 and ran into a few snags so I leveraged Josh's article to help me clear a few hurdles in the process.
Here are some links that I used to gather information and/or help me with the journey. Thanks to all of you that wrote the below!
First a quick overview:
What did I actually do:
C:\Users\danie\AppData\Roaming
C:\Users\danie\AppData\Roaming\Mist
C:\Users\danie\AppData\Roaming\Ethereum
We want to create a private network so create a new directory: dantest at: C:\Users\danie\AppData\Roaming\Ethereum\dantest
Create a new file named: DanCustomGenesis.json and place it at: C:\Users\danie\AppData\Roaming\Ethereum\dantest
Add the following to DanCustomGenesis.json. This is the genesis file that allows us to bootstrap the private network.
{
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
}
}
C:\Users\danie\AppData\Roaming\Mist\binaries\Geth\unpacked\geth --datadir "C:\\Users\\danie\\AppData\\Roaming\\Ethereum\\dannet" init "C:\\Users\\danie\\AppData\\Roaming\\Ethereum\\dannet\\DanCustomGenesis.json"
PAUSE
C:\Users\danie\AppData\Roaming\Mist\binaries\Geth\unpacked\geth --networkid 1234 --identity dantestnode --verbosity 3 --nodiscover --nat none --datadir="C:\\Users\\danie\\AppData\\Roaming\\Ethereum\\dannet"
PAUSE
geth attach
personal.newAccount("password")
miner.setEtherbase(personal.listAccounts[0])
miner.start()
eth.accounts
primary = eth.accounts[0]
balance = web3.fromWei(eth.getBalance(primary), "ether");
contract MyToken {
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
/* Initializes contract with initial supply tokens to the creator of the contract */
function MyToken(
uint256 initialSupply
) {
balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
}
/* 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
}
}
personal.unlockAccount(web3.eth.accounts[0]);
var initialSupply = 10000 ;
var untitled_mytokenContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"initialSupply","type":"uint256"}],"payable":false,"type":"constructor"}]);
var untitled_mytoken = untitled_mytokenContract.new(
initialSupply,
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000c57fe5b60405160208061030a833981016040528080519060200190919050505b80600060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b505b61028b8061007f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806370a0823114610046578063a9059cbb14610090575bfe5b341561004e57fe5b61007a600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506100cf565b6040518082815260200191505060405180910390f35b341561009857fe5b6100cd600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506100e7565b005b60006020528060005260406000206000915090505481565b80600060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561013357610000565b600060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205481600060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540110156101c057610000565b80600060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555080600060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055505b50505600a165627a7a7230582097cdec5f88d4e9e72bdc2bdfaf26e619c61d250d294c98688f9f439b0450da480029',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
This ends our ethereum experiment. There is so much more to learn and understand but hopefully this helps someone out there get started. If you are experimenting with ethereum let us know what you are building in the comments and if you have any tips/feedback on the information above. I would especially like to understand what I did to get the "No data is deployed on the contract address!" error. But the great thing about errors like that is that it sends one down a different path and I was able to play with the Remix IDE.
Hopefully you enjoyed, if you have questions/comments please send them along below. Happy blockchain'ing!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's work together to reach your goals. Contact us at the links below and a representative will be in touch.
We are here to help you and your business. Contact us using the button below.
Learn more©2020 FIS. Advancing the way the world pays, banks and invests™