Bitcoin and Ethereum are different design ideas for account systems. So their transaction systems are not the same.
Today, I will ignore Bitcoin and more explain about Ethereum.
If you ask me what is the blockchain, I will say the blockchain looks like a simple account book. It records one line of transfer records. Every record least includes three elements:
In the blockchain world, the wallet address is an identity on transfer records.
If you have one wallet address, you could get a ticket to visit the blockchain world.
Ethereum has two account types:
Both account types can:
The address format for both accounts is a 42-character hexadecimal string starting with 0x.
etc.
0x5e97870f263700f46aa00d967821199b9bc5a120
0x06012c8cf97bead5deae237070f9587f8e7a266d
Private Key -> Public Key -> Address.
Therefore, address generation requires three steps:
Private Key -> Public Key -> Address.
Therefore, address generation requires three steps:
First, install sha3sum
for keccak-256sum
.
https://github.com/maandree/sha3sum
// on macOS
brew install sha3sum
# Generate the private and public keys
openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > key
# Extract the public key and remove the EC prefix 0x04
cat key | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//' > pub
# Extract the private key and remove the leading zero byte
cat key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
# Generate the hash and take the address part
cat pub | keccak-256sum -x -l | tr -d ' -' | tail -c 41 | awk '{print "0x"$1}'> address
# display your address
cat address
package main
import (
"crypto/ecdsa"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
}
privateKeyBytes := crypto.FromECDSA(privateKey)
fmt.Println("SAVE BUT DO NOT SHARE THIS (Private Key):", hexutil.Encode(privateKeyBytes))
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}
publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA)
fmt.Println("Public Key:", hexutil.Encode(publicKeyBytes))
address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()
fmt.Println("Address:", address)
}
Now we have two easy ways to generate the Ethereum wallet address offline and have the private key.