Wallets of Ethereum
Wallets of Ethereum
A private key is a secure and secret number that helps users to secure their
digital money and also allows them to make transactions and generate the
receiving addresses.
It is an integral part of the Ethereum Network as this secret number
acts as a secure password that protects the user from unauthorized
access to their funds.
A private key provides a very high level of security as it can take years
and years to crack a private key.
The private key is only known to the user and is used to carry out any
cryptocurrency transaction from their account.
Private keys can derive public keys and hence public keys can derive
Ethereum addresses but the same cannot be said for vice-versa as it is
not possible to derive public keys from Ethereum addresses and private
keys from public keys.
Prerequisites
Javascript
const EC = require('elliptic').ec;
const BN = require('bn.js')
const G = ec.g;
const x = pp.getX().toBuffer();
const y = pp.getY().toBuffer();
const bt = Buffer.concat([x,y])
const kc = keccak256(bt)
Output:
Address is c5ed5d9b9c957be2baa01c16310aa4d1f8bc8e6f
Step 4: After getting the output, just add 0x at the start of the address and
your Ethereum Wallet Address is ready.
0xc5ed5d9b9c957be2baa01c16310aa4d1f8bc8e6f
Explanation:
The code starts by creating a new EC object.
This is an elliptic curve that secp256k1 uses.
The EC object is then used to create a BN object called SK, which has
16 bytes of entropy.
The code then creates a G object that is initialized with ec curve’s
generator point (G=ec.g).
The code then multiplies this private key by G, which is ec’s
multiplication function for Elliptic Curve Groups (ECG).
Then x and y are created from pp using getX() and getY().
Then, it gets x and y from G’s mul function which returns two value on
the curve: X and Y
Then bt is created as an array of bytes that contains x and y and are
then concatenated into one buffer using Buffer.concat().
Now, keccak256 is used to hash this buffer to get kc as its result.
Finally, ethereumAddress is created by taking kc and converting it into
hexadecimal string format before returning it to display in the console
window.
The code above will then concatenate the hex string representation of
the keccak256 hash to a buffer and return it as an Ethereum address.
The code is a simple example of how to create an Ethereum Address.
Javascript
console.log(privateKeyToPublicKey(Buffer.from(
'4f3edf983ac986a65a342ce7c78d9ac076d3b113bce9c46f30d7d25171b32b1d',
'hex')).toString('hex'))
Output:
04c1573f1528638ae14cbe04a74e6583c5562d59214223762c1a11121e2461
9cbc09d27a7a1cb989dd801cc028dd8225f8e2d2fd57d852b5bf697112f69b62
29d1
After getting the public key, import the publicKeyToAddress module and
again apply console.log in order to get the address.
Javascript
console.log(publicKeyToAddress(Buffer.from(
'04c1573f1528638ae14cbe04a74e6583c5562d59214223762c1a11121e24619cbc09d27a7a1cb989dd801cc
'hex')))
Output:
0xAf3CD5c36B97E9c28c263dC4639c6d7d53303A13
Explanation:
The first code starts by requiring the privateKeyToPublicKey module.
The code then uses that module to convert a private key into its
corresponding public key.
The first line of the program is
console.log(privateKeyToPublicKey(Buffer.from(‘4f3edf983ac636a65a842
ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d’,’hex’)).toString(‘hex’
)) which converts the private key to public key.
Step 3 starts by requiring the publicKeyToAddress function.
This function takes a public key and returns an address for it.
The code then prints out the result of calling this function with the hex
string
04c1573f1528638ae14cbe04a74e6583c5562d59214223762c1a11121e2
4619cbc09d27a7a1cb989dd801cc028dd8225f8e2d2fd57d852b5bf697112
f69b6229d1
The code generates an address for the public key of
04c1573f1528638ae14cbe04a74e6583c5562d59214223762c1a11121e2
4619cbc09d27a7a1cb989dd801cc028dd8225f8e2d2fd57d852b5bf697112
f69b6229d1
The code is a method that takes in a private key and returns the
address of the corresponding Ethereum
Smart Contract (or cryptocontract) is a computer program that directly and
automatically controls the transfer of digital assets between the parties under
certain conditions. A smart contract works in the same way as a traditional
contract while also automatically enforcing the contract. Smart contracts are
programs that execute exactly as they are set up(coded, programmed) by
their creators. Just like a traditional contract is enforceable by law, smart
contracts are enforceable by code.
The bitcoin network was the first to use some sort of smart contract by
using them to transfer value from one person to another.
The smart contract involved employs basic conditions like checking if
the amount of value to transfer is actually available in the sender
account.
Later, the Ethereum platform emerged which was considered more
powerful, precisely because the developers/programmers could make
custom contracts in a Turing-complete language.
It is to be noted that the contracts written in the case of the bitcoin
network were written in a Turing-incomplete language, restricting the
potential of smart contracts implementation in the bitcoin network.
There are some common smart contract platforms like Ethereum,
Solana, Polkadot, Hyperledger fabric, etc.
History:
In 1994, Nick Szabo, a legal scholar, and a cryptographer recognized the
application of a decentralized ledger for smart contracts. He theorized that
these contracts could be written in code which can be stored and replicated
on the system and supervised by the network of computers that constitute
the blockchain. These smart contracts could also help in transferring digital
assets between the parties under certain conditions.
Features of Smart Contracts
The following are some essential characteristics of a smart contract:
1. Distributed: Everyone on the network is guaranteed to have a copy of
all the conditions of the smart contract and they cannot be changed by
one of the parties. A smart contract is replicated and distributed by all the
nodes connected to the network.
2. Deterministic: Smart contracts can only perform functions for which
they are designed only when the required conditions are met. The final
outcome will not vary, no matter who executes the smart contract.
3. Immutable: Once deployed smart contract cannot be changed, it can
only be removed as long as the functionality is implemented previously.
4. Autonomy: There is no third party involved. The contract is made by
you and shared between the parties. No intermediaries are involved
which minimizes bullying and grants full authority to the dealing parties.
Also, the smart contract is maintained and executed by all the nodes on
the network, thus removing all the controlling power from any one party’s
hand.
5. Customizable: Smart contracts have the ability for modification or we
can say customization before being launched to do what the user wants it
to do.
6. Transparent: Smart contracts are always stored on a public
distributed ledger called blockchain due to which the code is visible to
everyone, whether or not they are participants in the smart contract.
7. Trustless: These are not required by third parties to verify the integrity
of the process or to check whether the required conditions are met.
8. Self-verifying: These are self-verifying due to automated possibilities.
9. Self-enforcing: These are self-enforcing when the conditions and
rules are met at all stages.
A smart contract is just a digital contract with the security coding of the
blockchain.
It has details and permissions written in code that require an exact
sequence of events to take place to trigger the agreement of the terms
mentioned in the smart contract.
It can also include the time constraints that can introduce deadlines in
the contract.
Every smart contract has its address in the blockchain. The contract
can be interacted with by using its address presuming the contract has
been broadcasted on the network.
The idea behind smart contracts is pretty simple. They are executed on a
basis of simple logic, IF-THEN for example:
IF you send object A, THEN the sum (of money, in cryptocurrency) will
be transferred to you.
IF you transfer a certain amount of digital assets (cryptocurrency, for
example, ether, bitcoin), THEN the A object will be transferred to you.
IF I finish the work, THEN the digital assets mentioned in the contract
will be transferred to me.
Note: The WHEN constraint can be added to include the time factor in the
smart contracts. It can be seen that these smart contracts help set conditions
that have to be fulfilled for the terms of the contract agreement to be
executed. There is no limit on how much IF or THEN you can include in your
intelligent contract.
Smart Contract Working
Identify Agreement: Multiple parties identify the cooperative
opportunity and desired outcomes and agreements could include
business processes, asset swaps, etc.
Set conditions: Smart contracts could be initiated by parties
themselves or when certain conditions are met like financial market
indices, events like GPS locations, etc.
Code business logic: A computer program is written that will be
executed automatically when the conditional parameters are met.
Encryption and blockchain technology: Encryption provides secure
authentication and transfer of messages between parties relating to smart
contracts.
Execution and processing: In blockchain iteration, whenever
consensus is reached between the parties regarding authentication and
verification then the code is executed and the outcomes are memorialized
for compliance and verification.
Network updates: After smart contracts are executed, all the nodes
on the network update their ledger to reflect the new state. Once the
record is posted and verified on the blockchain network, it cannot be
modified, it is in append mode only.