Skip to content

Instantly share code, notes, and snippets.

@cuiweixie
Created November 12, 2025 08:16
Show Gist options
  • Select an option

  • Save cuiweixie/e5ee2b34b3216c90e326ab6dd301edfe to your computer and use it in GitHub Desktop.

Select an option

Save cuiweixie/e5ee2b34b3216c90e326ab6dd301edfe to your computer and use it in GitHub Desktop.
gen_enode.go
package main
import (
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/enode"
)
func main() {
// 你的 nodekeyhex(私钥)
nodekeyHex := "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
// 1. 加载私钥
privateKey, err := crypto.HexToECDSA(nodekeyHex)
if err != nil {
panic(err)
}
// 2. 获取公钥(node_id)
publicKey := privateKey.Public().(*ecdsa.PublicKey)
nodeID := enode.PubkeyToIDV4(publicKey)
// 3. 构建 enode URL
host := "op-sequencer-seq"
port := 30303
enodeURL := fmt.Sprintf("enode://%x@%s:%d", nodeID, host, port)
fmt.Println("Node ID:", nodeID.String())
fmt.Println("Enode URL:", enodeURL)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment