# How to Create a BSV Address in Golang

Once you’ve generated an **ECDSA public–private key pair**, deriving a **BSV address** from the public key follows a simple process.

Example Implementation in GoLang

```
package main 

import ( 
    "fmt" 
    "github.com/libsv/go-bk/bec" 
    "github.com/libsv/go-bk/crypto" 
    "github.com/libsv/go-bt/v2/bscript" 
)   

func main() { 
    privKey, _ := bec.NewPrivateKey(bec.S256()) 

    // 1. Serialize the public key (compressed form recommended)
    pubKey := privKey.PubKey().SerialiseCompressed() 

    // 2. Apply SHA-256
    pubKey = crypto.Sha256(pubKey) 

    // 3. Apply RIPEMD-160
    pubKey = crypto.Ripemd160(pubKey)   

    // 4. Prepend version byte (0x00 for mainnet, 0x4d for testnet)
    version := []byte{0x00}  
    pubKey = append(version, pubKey...)  

    // 5. Encode in Base58Check (with checksum)
    address := bscript.Base58EncodeMissingChecksum(pubKey)   

    // 6. Print result
    fmt.Printf("Address: %s\n", address) 
} 
```

&#x20;

#### Step-by-Step Process

1. **Get the compressed x-coordinate of the public key**

   &#x20;`pKey := pubKey.SerialiseCompressed()`&#x20;
2. **Hash the result with SHA-256**

   &#x20;`pKey = crypto.Sha256(pKey)`&#x20;
3. **Hash again with RIPEMD-160** → this is the **Public-Key-Hash (PKH)**

   &#x20;`pubKey = crypto.Ripemd160(pubKey)`&#x20;
4. **Add version byte** → identifies the network

   * `0x00` for **mainnet**
   * `0x4d` for **testnet**

   &#x20;`version := []byte{0x00} pubKey = append(version, pubKey...)`&#x20;
5. **Generate checksum and encode with Base58Check**

   &#x20;`address := bscript.Base58EncodeMissingChecksum(pubKey)`&#x20;
6. **Output the final address**

   &#x20;`fmt.Printf("Address: %s\n", address)`

&#x20;

✅ **Summary:**\
Creating a **BSV address** involves hashing a compressed public key with **SHA-256 then RIPEMD-160**, adding a **version byte**, and encoding the result in **Base58Check**. This produces a short, readable, and error-resistant address ready to use on the network.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hub.bsvblockchain.org/higher-learning/bsv-academy/bitcoin-primitives-hash-functions/ripemd-160-overview/how-to-create-a-bsv-address-in-golang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
