Creating (and Debugging) Your Own Blockchain

So many people talk about blockchain and DLTs (Distributed Ledger Technology), but have little idea about what happens underneath. This can…

Creating (and Debugging) Your Own Blockchain

So many people talk about blockchain and DLTs (Distributed Ledger Technology), but have little idea about what happens underneath. This can often lead to a naive approach. So, let’s create our own blockchain, and test it. First, we open up remix (https://remix.ethereum.org/) and add our smart contract. This contact just has four methods which can be used to add [add()], subtract [sub()], multiply [mul()], square [sqr()] and take a square root [sqrt()]:

Now, we need to install Ganache (https://trufflesuite.com/ganache/index.html). After this is installed we can run Ganache, and we should see that it has created a new blockchain for us:

This includes 10 accounts, and which each has 100 Eth in its account. These accounts can then be used to perform transactions on the blockchain. The server places itself on a certain port. In the example above, this port is TCP port 8545. This port will be used to connect from Remix to our blockchain and deploy our smart contract.

Next, we compile the smart contract:

And if we get no errors, we can now deploy the contact to our blockchain. For this we now select the Deployment tab, and then for the Environment we select “Web3 Provider”. It should then pick up the first account address:

We should be all good to now deploy by clicking on the “Deploy” button, and Remix should give us a message that it has deployed the contract successfully.

Once we deploy our contact, we can use Remix to test it. In the following we see we can test the add() method for the contact, and add 5 and 3, with a result of 8:

And if you have the Geth console installed, you can also interact with the console:

And that’s it! Once you have tested it, you probably now want to go to a test network and deploy it there:

https://asecuritysite.com/ethereum/ethereum01