> For the complete documentation index, see [llms.txt](https://hub.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hub.bsvblockchain.org/higher-learning/bsv-academy/bitcoin-primitives-hash-functions/ripemd-160-overview/how-to-create-a-bsv-address-in-golang.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
