Skip to main content

Posts

Smart contract with remix IDE and Ganache

  Previous Topic:  Simple transaction with ganache using Golang In the Previous topic, we learned how to do transaction with ganache using Golang. Now, we will learn what is smart contract and how to write smart contract and how to deploy it and how to call the contract using remix. To learn what is smart contract, we already write a blog about that. Please feel free to take a look.  Ethereum Smart contract . For beginners, use the Remix IDE for learning smart contract and understand how it works. Then we will use Truffle framework. REMIX:  Remix IDE Link Remix will provide a default workspace for developing smart contract. Now you can able to create a new file and start writing contracts, compile it with solidity compiler and deploy that contract and test the contracts. Simple Smart Contract: First create new file called store.sol  and start writing a simple contract. Contract Functionality: Store a record using SetRecord method. View the latest record . [record variable is public wh
Recent posts

Transactions on Ganache using Golang

  Previous Topic:  Connect to Ganache using golang In the pervious topic, we showed how to connect with ganache and retrieving balance for the account using Golang. Now, we are going to transfer some ethers from one account to another account using Golang. Transfer Fund: Here we are going to transfer 5 ethers, From Address :  0x532205E897418D09F2C0253E5A31e666eE87cb1A To Address :  0x3fCf008C3d40C0af410CD122F00eFA77288A2E13 Each account has balance of 100 eth. First, we need to find the nonce of the From Address and generate the unsigned raw transaction and using the private key of the From Address sign the unsigned raw transaction.  To get the Private Key follow the steps: 1. Click the show keys. 2. We will able to see the private key details of the respective address. After Signing the transaction, we need to broadcast that signed transaction in the network. package main import ( "context" "fmt" "log" "math/big" "strings" &q

Connect to Ganache using Golang

Previous Topic:  Ganache Overview Connect to Ganache: We are going use the go-ethereum - ethclient package to make a connection with the ganache server using Golang. go get github.com/ethereum/go-ethereum/ethclient In the below example, we are just simply connecting with ganache server and retrieve the chain Id value from the server. package main import ( "context" "fmt" "log" "github.com/ethereum/go-ethereum/ethclient" ) func main() { client, err := ethclient.Dial("http://127.0.0.1:7545") if err != nil { log.Fatal(err) } fmt.Println("Connection with ganache successful") chainId, err := client.ChainID(context.Background()) if err != nil { log.Fatal(err) } fmt.Println("Chain Id :", chainId) } Output: Connection with ganache successful Chain Id : 1337 Retrieving Balance for the accounts: go get github.com/ethereum/go-ethereum/common In the below example, we are going to retrieve the balanc

Ganache Workspace Overview

Previous Topic:  Ganache Installation Ethereum Workspace Overview: After the workspace created, you will able to see the server details and list of accounts. Each account has 100 ether. There were some additional interface you can access: Accounts       - list of generated accounts and their balance [default view] Blocks       - shows each block mined on the blockchain, along with gas used and transactions. Transactions       - list all the transactions on the blockchain network Contracts      - list the contracts contains in the workspace only when the workspace is connected with a             truffle project. Logs      - shows the logs for the server which is helpful for debugging  Events      - list all the events triggered since the workspace created. How to Connect with Local Ganache Server? In the Ganache UI, you can able to see the server details. you can directly use that sever port to connect your application with ganache . RPC Server : http://127.0.0.1:7545 Next Topic:   Conn

What is GANACHE and How to install?

Ganache is a personal blockchain for rapid Ethereum distributed application development. You can use Ganache across the entire development cycle; enabling you to develop, deploy, and test your dApps in a safe and deterministic environment. Ganache comes in two favours: a UI and CLI. Ganache UI is a desktop application supporting Ethereum technology. Features: Fast and efficient for testing  offers Ethereum Json RPC Mine block instantly and fast forward time Easy to use. It has UI desktop application which helps us to understand what is happening in broader view. Installation on Windows: Step 1: Go to this page:  https://trufflesuite.com/ganache/  and click the download. Step 2: Once downloaded, Open that file and click install. It will install the ganache CLI and UI desktop application on the windows. Step 3: After the installation, Ganache application is now available.  If you have problem after the installation, Go to settings -- Installed Apps -- Ganache and Scroll down and click Re

Crypto ED25519 Signing and Verifying using Golang

The Edwards-curve Digital Signature Algorithm (ECDSA) is used to create a digital signature using an enhancement of the Schnorr signature with Twisted Edwards curves. Overall it is faster that many other digital signature methods, and is strong for security. One example of ECDSA is Ed25519, and which is based on Curve 25519. It generates a 64-byte signature value of (R,s), and has 32-byte values for the public and the private keys. Example : package main import ( "crypto/ed25519" "crypto/rand" "encoding/hex" "fmt" "log" ) func main() { publickey, privatekey, err := ed25519.GenerateKey(rand.Reader) if err != nil { fmt.Println("cannot generate ecdsa keys") log.Fatal(err) } msg := "hello" signedBytes := ed25519.Sign(privatekey, []byte(msg)) fmt.Println("Signed Message :", hex.EncodeToString(signedBytes)) if !ed25519.Verify(publickey, []byte(msg), signedBytes) { fmt.Println("ver

Ethereum Smart contract

Smart contract is a self executing program based on agreement or logic we provided in the program. There are three types of contract: Smart Legal Contracts           - Digital Will, A legal agreement between two parties  Decentralized Autonomous Organizations (DAO)         - No One is boss. Decisions are made based on voting (smart contract)  Application Logic Contracts         - Communication with smart devices through contracts (IOT) Each Contract lives on the Ethereum network and has an unique address with ether balance. If we want execute something on the contract we need to use the contract address to do actions. It has data and code associated with it Similar to OOPS concept. Ethereum nodes don't run the solidity code. First, Transforms the code to bytecode and deploy it in the network. Each nodes has EVM which will executes the bytecode. Languages to write contracts:   Solidity  - Javascript like Vyper     - Python like Contract Limitations:  Anyone can validate transaction

Blockchain in Decentralized Finance

How Decentralized finance differs from Centralized finance? Centralized Finance: Issue with Centralized finance: Requires Total trust  Slow Transactions  High Maintenance fee charges  Decentralized Finance: Main Characteristics of Bitcoin: Public Registry of assets and transactions. Autonomous. Controlled by software Permissionless Cryptographically secure, unmodified and unforgeable Operations to do on Blockchain: ✔ Reads Historical Transactions ✔ Create new transactions ✖ Update transaction ✖   Delete transaction

Ethereum Overview

Origin of Ethereum:  At Some point Blockchain technology became very popular. One Blockchain per Application. It's very difficult to create our own blockchain for every new applications. Ethereum concept came here, it's aim to create a single blockchain for that will allow to create any kind of new applications on top of it.   History of Ethereum: 2013 - Ethereum whitepaper by Vitalik buterin   2014 - Ethereum Development 2015 - Olympic Release Eth network was created 2020 - Boom in DeFi Activities 2022 - The Merge Upgrade of Execution layer Overview: Ethereum Projects: AUGUR - Prediction Market OPENSEA - digital collectibles UNISWAP - Assets Exchange COMPOUND - Leading platform Decentralized Application : Ethereum allows us to build new applications called Decentralized Applications . Just as regular applications, they run on multiple machines. But what differs them is that these machines are not owned by single group or organization. They are owned by different people in diff

Crypto RSA Signing and Verification in Golang

  RSA [Rivest-shamir-Adleman] encryption is one of the most widely used algorithms for secure data encryption. Signing and Verification:   RSA works by generating form of key pair of private and public keys. For Signing:  we need to provide some inputs,  A random reader used for generating random bits because if we provide the same input, it doesn't give the same output as last time. Before signing, we need to hash our message. we also need to provide which hash function is used for message hashing. Finally, private key.  For Verifying: we need to provide some inputs,  hash of our message. which hash function is used for message hashing while signing. Finally, public key and signature what we obtained while signing.  Example: package main import ( "crypto" "crypto/rand" "crypto/rsa" "crypto/sha256" "encoding/hex" "fmt" "log" ) func main() { privatekey, publickey := GenerateRsaKeys() message := "