ifunjoke / Golang-Ethereum-Personal-Sign

A simple Golang solution for MetaMasks personal_sign method.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Golang Ethereum Personal Sign

Go Reference Go Report Card

A simple Golang solution for MetaMasks personal_sign method (https://docs.metamask.io/guide/signing-data.html#a-brief-history). Create a MetaMask signature for comparison: https://app.mycrypto.com/sign-message

Usage

Install:

go get github.com/etaaa/Golang-Ethereum-Personal-Sign

Usage:

package main

import (
	"fmt"
	"log"
	"os"
	"testing"

	"github.com/ethereum/go-ethereum/crypto"
	"github.com/joho/godotenv"

	ps "github.com/etaaa/Golang-Ethereum-Personal-Sign"
)

func main() {
	// Load private key from .env file
	err := godotenv.Load()
	if err != nil {
		log.Fatal(err)
	}
	privateKeyString := os.Getenv("PRIVATE_KEY")
	// Parse private key
	privateKey, err := crypto.HexToECDSA(privateKeyString)
	if err != nil {
		log.Fatal(err)
	}
	// Sign message
	signature, err := ps.PersonalSign("Hello World.", privateKey)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(signature)
}

Questions

For any questions feel free to DM me on Discord (@itseta).

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

MIT

About

A simple Golang solution for MetaMasks personal_sign method.

License:MIT License


Languages

Language:Go 100.0%