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). 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"

	sign "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 := sign.PersonalSign("Hello World.", privateKey)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(signature)
}

Questions

For any questions feel free to add and DM me on Discord (eta#0001).

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

GitHub

View Github