-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add xrpl-go examples and references to xrpl-dev-portal #3211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
<div className="col langs"> | ||
<Link to="/docs/tutorials/go/"> | ||
<img | ||
alt="GoLang Logo" | ||
src={require("../static/img/logos/golang.svg")} | ||
className="circled-logo" | ||
/> | ||
<h5 className="btn-arrow">{translate("GoLang")}</h5> | ||
</Link> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is duplicated?
@@ -13,6 +13,7 @@ For other programming languages, you can access the XRP Ledger through the [HTTP | |||
| Language | Library Name | Get Started | API Reference | Source Code | | |||
|---------------------------------|---------------------------|-------------|--------------|-------------| | |||
| **Python** | `xrpl-py` | [Get Started Using Python](../tutorials/python/build-apps/get-started.md) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) | | |||
| **GoLang** | `xrpl-go` | [Get Started Using Go](../tutorials/go/build-apps/get-started.md) | [API Reference](https://pkg.go.dev/github.com/Peersyst/xrpl-go) | [Repo](https://github.com/Peersyst/xrpl-go) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stick with the official name, "Go".
| **GoLang** | `xrpl-go` | [Get Started Using Go](../tutorials/go/build-apps/get-started.md) | [API Reference](https://pkg.go.dev/github.com/Peersyst/xrpl-go) | [Repo](https://github.com/Peersyst/xrpl-go) | | |
| **Go** | `xrpl-go` | [Get Started Using Go](../tutorials/go/build-apps/get-started.md) | [API Reference](https://pkg.go.dev/github.com/Peersyst/xrpl-go) | [Repo](https://github.com/Peersyst/xrpl-go) | |
showcase_icon: assets/img/logos/golang.svg | ||
--- | ||
|
||
# Get Started Using GoLang Library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Get Started Using GoLang Library | |
# Get Started Using Go Library |
@@ -16,6 +16,8 @@ Use these libraries to access the XRP Ledger from your programming language of c | |||
|
|||
{% xrpl-card title="Python" body="xrpl.py - a pure Python library" href="https://xrpl-py.readthedocs.io/" image="/img/logos/python.svg" imageAlt="Python logo" /%} | |||
|
|||
{% xrpl-card title="GoLang" body="xrpl.go - a pure GoLang library" href="https://pkg.go.dev/github.com/Peersyst/xrpl-go" image="/img/logos/golang.svg" imageAlt="GoLang logo" /%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% xrpl-card title="GoLang" body="xrpl.go - a pure GoLang library" href="https://pkg.go.dev/github.com/Peersyst/xrpl-go" image="/img/logos/golang.svg" imageAlt="GoLang logo" /%} | |
{% xrpl-card title="Go" body="xrpl.go - a pure Go library" href="https://pkg.go.dev/github.com/Peersyst/xrpl-go" image="/img/logos/golang.svg" imageAlt="Go logo" /%} |
@@ -469,6 +476,9 @@ | |||
- label: Ruby Client Library | |||
href: https://www.rubydoc.info/gems/xrbp | |||
external: true | |||
- label: GoLang Client Library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- label: GoLang Client Library | |
- label: Go Client Library |
@@ -16,7 +16,7 @@ These tutorials walk you through the basics of building a very simple XRP Ledger | |||
|
|||
{% xrpl-card title="Python" body="Using xrpl.py, a pure Python library." href="/docs/tutorials/python/" image="/img/logos/python.svg" imageAlt="Python logo" /%} | |||
|
|||
<br/> | |||
{% xrpl-card title="GoLang" body="Using xrpl-go, a pure GoLang library." href="/docs/tutorials/go/" image="/img/logos/golang.svg" imageAlt="GoLang logo" /%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% xrpl-card title="GoLang" body="Using xrpl-go, a pure GoLang library." href="/docs/tutorials/go/" image="/img/logos/golang.svg" imageAlt="GoLang logo" /%} | |
{% xrpl-card title="Go" body="Using xrpl-go, a pure Go library." href="/docs/tutorials/go/" image="/img/logos/golang.svg" imageAlt="Go logo" /%} |
<div className="col langs"> | ||
<Link to="/docs/tutorials/go/"> | ||
<img | ||
alt="GoLang Logo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alt="GoLang Logo" | |
alt="Go Logo" |
|
||
## Requirements | ||
|
||
Requiring Go version `1.22.0` and later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring Go version `1.22.0` and later. | |
To follow this tutorial, you should have Go version `1.22.0` or later installed. |
## Requirements | ||
|
||
Requiring Go version `1.22.0` and later. | ||
[Download latest Go version](https://go.dev/dl/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Download latest Go version](https://go.dev/dl/) | |
[Download latest Go version](https://go.dev/dl/). |
1. [Connect to the XRP Ledger.](#1-connect-to-the-xrp-ledger) | ||
1. [Get an account.](#2-get-account) | ||
1. [Query the XRP Ledger.](#3-query-the-xrp-ledger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. [Connect to the XRP Ledger.](#1-connect-to-the-xrp-ledger) | |
1. [Get an account.](#2-get-account) | |
1. [Query the XRP Ledger.](#3-query-the-xrp-ledger) | |
1. [Connect to the XRP Ledger.](#1.-connect-to-the-xrp-ledger) | |
2. [Get an account.](#2.-get-account) | |
3. [Query the XRP Ledger.](#3.-query-the-xrp-ledger) |
|
||
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl-go`, you have two main options: | ||
|
||
1. Via `websocket`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Via `websocket`: | |
1. Via WebSocket: |
|
||
### 2. Get account | ||
|
||
In `xrpl-go`, account creation and key management live in the wallet package, and on Testnet you can use the built-in faucet provider on your WebSocket (or RPC) client to fund a brand-new account immediately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In `xrpl-go`, account creation and key management live in the wallet package, and on Testnet you can use the built-in faucet provider on your WebSocket (or RPC) client to fund a brand-new account immediately. | |
In `xrpl-go`, account creation and key management live in the `wallet` package, and on Testnet you can use the built-in faucet provider on your WebSocket (or RPC) client to fund a brand-new account immediately. |
return | ||
} | ||
|
||
fmt.Println("✅ Batch transaction submitted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid using emojis in the example code. Some environments may not render emojis reliably, and it keeps our examples universally readable.
<div className="col langs"> | ||
<Link to="/docs/tutorials/go/"> | ||
<img | ||
alt="GoLang Logo" | ||
src={require("../static/img/logos/golang.svg")} | ||
className="circled-logo" | ||
/> | ||
<h5 className="btn-arrow">{translate("GoLang")}</h5> | ||
</Link> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<div className="col langs"> | |
<Link to="/docs/tutorials/go/"> | |
<img | |
alt="GoLang Logo" | |
src={require("../static/img/logos/golang.svg")} | |
className="circled-logo" | |
/> | |
<h5 className="btn-arrow">{translate("GoLang")}</h5> | |
</Link> | |
</div> |
Remove this duplicate.
html: get-started-using-golang-library.html | ||
parent: golang.html | ||
funnel: Build | ||
doc_type: Tutorials | ||
category: Get Started |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
html: get-started-using-golang-library.html | |
parent: golang.html | |
funnel: Build | |
doc_type: Tutorials | |
category: Get Started |
You can remove these frontmatter values.
top_nav_grouping: Get Started | ||
labels: | ||
- Development | ||
showcase_icon: assets/img/logos/golang.svg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showcase_icon: assets/img/logos/golang.svg |
html: build-apps-in-golang.html | ||
parent: golang.html | ||
top_nav_grouping: Article Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
html: build-apps-in-golang.html | |
parent: golang.html | |
top_nav_grouping: Article Types |
You can remove this frontmatter--it's deprecated.
html: golang.html | ||
parent: tutorials.html | ||
top_nav_grouping: Article Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
html: golang.html | |
parent: tutorials.html | |
top_nav_grouping: Article Types |
@@ -328,6 +359,10 @@ To know for sure what a transaction did, you must look up the outcome of the tra | |||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Check" language="php" /%} | |||
{% /tab %} | |||
|
|||
{% tab label="GoLang" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% tab label="GoLang" %} | |
{% tab label="Go" %} |
@@ -391,6 +426,16 @@ print_r("Seed: " . $wallet->getSeed()); // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoU | |||
``` | |||
{% /tab %} | |||
|
|||
{% tab label="GoLang" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% tab label="GoLang" %} | |
{% tab label="Go" %} |
fmt.Println("🌐 Classic Address:", wallet.ClassicAddress) // Example: r9ESeQQswbTxV8neiDTLTHXbXfUwiihyJk | ||
fmt.Println("🌐 Seed:", wallet.Seed) // Example: sEd7XGFGSWteam777HQHvw7vHypEWy2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Println("🌐 Classic Address:", wallet.ClassicAddress) // Example: r9ESeQQswbTxV8neiDTLTHXbXfUwiihyJk | |
fmt.Println("🌐 Seed:", wallet.Seed) // Example: sEd7XGFGSWteam777HQHvw7vHypEWy2 | |
fmt.Println("Classic Address:", wallet.ClassicAddress) // Example: r9ESeQQswbTxV8neiDTLTHXbXfUwiihyJk | |
fmt.Println("Seed:", wallet.Seed) // Example: sEd7XGFGSWteam777HQHvw7vHypEWy2 |
@@ -433,6 +478,20 @@ $client = new JsonRpcClient("https://xrplcluster.com"); | |||
``` | |||
{% /tab %} | |||
|
|||
{% tab label="GoLang" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% tab label="GoLang" %} | |
{% tab label="Go" %} |
@@ -469,6 +528,20 @@ $client = new JsonRpcClient("http://localhost:5005"); | |||
``` | |||
{% /tab %} | |||
|
|||
{% tab label="GoLang" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% tab label="GoLang" %} | |
{% tab label="Go" %} |
@@ -8,3 +8,4 @@ For more context, see the Get Started tutorial for your preferred language: | |||
- [Java](https://xrpl.org/get-started-using-java.html) | |||
- [JavaScript](https://xrpl.org/get-started-using-javascript.html) | |||
- [PHP](https://xrpl.org/get-started-using-php.html) | |||
- [GoLang](https://xrpl.org/get-started-using-golang.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [GoLang](https://xrpl.org/get-started-using-golang.html) | |
- [Go](https://xrpl.org/get-started-using-go.html) |
```go | ||
// Define the network client | ||
client := websocket.NewClient(websocket.NewClientConfig(). | ||
WithHost("wss://s.altnet.rippletest.net:51233")) | ||
|
||
// Disconnect the client when done. (Defer executes at the end of the function) | ||
defer client.Disconnect() | ||
|
||
// Connect to the network | ||
if err := client.Connect(); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have a code sample for this (_code-samples/get-started/go/base/ws/main.go), please use the code-snippet
tag to reference the snippet instead.
For example:
1. Via WebSocket:
{% code-snippet file="/_code-samples/get-started/go/base/ws/main.go" from="func main()" language="go" /%}
2. Via `RPC`: | ||
```go | ||
cfg, err := rpc.NewClientConfig("https://s.altnet.rippletest.net:51234/") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Initiate the network client | ||
client := rpc.NewClient(cfg) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Via `RPC`: | |
```go | |
cfg, err := rpc.NewClientConfig("https://s.altnet.rippletest.net:51234/") | |
if err != nil { | |
panic(err) | |
} | |
// Initiate the network client | |
client := rpc.NewClient(cfg) | |
``` | |
2. Via RPC: | |
{% code-snippet file="/_code-samples/get-started/go/base/rpc/main.go" from="func main()" language="go" /%} |
client := websocket.NewClient(websocket.NewClientConfig(). | ||
WithHost("wss://s.altnet.rippletest.net:51233")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add the WithFaucetProvider()
function here since we are connecting to Testnet?
client := websocket.NewClient(websocket.NewClientConfig(). | |
WithHost("wss://s.altnet.rippletest.net:51233")) | |
client := websocket.NewClient(websocket.NewClientConfig(). | |
WithHost("wss://s.altnet.rippletest.net:51233"). | |
WithFaucetProvider(faucet.NewTestnetFaucetProvider()), | |
) |
|
||
func main() { | ||
// Define the network client configuration | ||
cfg, err := rpc.NewClientConfig("https://s.altnet.rippletest.net:51234/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add the WithFaucetProvider()
function here since we are connecting to Testnet?
cfg, err := rpc.NewClientConfig("https://s.altnet.rippletest.net:51234/") | |
cfg, err := rpc.NewClientConfig( | |
"https://s.altnet.rippletest.net:51234/", | |
rpc.WithFaucetProvider(faucet.NewTestnetFaucetProvider()), | |
) |
|
||
Now that you know how to use `xrpl.js` to connect to the XRP Ledger, get an account, and look up information about it, you can also: | ||
|
||
- [Send XRP](../../how-tos/send-xrp.md). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [Send XRP](../../how-tos/send-xrp.md). | |
- [Send XRP](../../how-tos/send-xrp.md). | |
{% raw-partial file="/docs/_snippets/common-links.md" /%} |
|
||
You can query the XRP Ledger to get information about [a specific account](../../../references/http-websocket-apis/public-api-methods/account-methods/index.md), [a specific transaction](../../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md), the state of a [current or a historical ledger](../../../references/http-websocket-apis/public-api-methods/ledger-methods/index.md), and [the XRP Ledger's decentralized exchange](../../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/index.md). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](../../../concepts/transactions/reliable-transaction-submission.md). | ||
|
||
You can use either the Client's `request()` method to access the XRP Ledger's [WebSocket API](../../../references/http-websocket-apis/api-conventions/request-formatting.md). For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this actually describes the Go code correctly. Change to:
You can use either the Client's `request()` method to access the XRP Ledger's [WebSocket API](../../../references/http-websocket-apis/api-conventions/request-formatting.md). For example: | |
Use the Client's `Request()` method to access the XRP Ledger's [WebSocket API](../../../references/http-websocket-apis/api-conventions/request-formatting.md). For example: |
```go | ||
import "github.com/Peersyst/xrpl-go/xrpl/websocket" | ||
const PublicServer = "wss://xrplcluster.com/" | ||
client := websocket.NewClient(websocket.NewClientConfig().WithHost(PublicServer)) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```go | |
import "github.com/Peersyst/xrpl-go/xrpl/websocket" | |
const PublicServer = "wss://xrplcluster.com/" | |
client := websocket.NewClient(websocket.NewClientConfig().WithHost(PublicServer)) | |
``` | |
```go | |
import "github.com/Peersyst/xrpl-go/xrpl/websocket" | |
const PUBLIC_SERVER = "wss://xrplcluster.com/" | |
func main() { | |
client := websocket.NewClient(websocket.NewClientConfig().WithHost(PUBLIC_SERVER)) | |
// ... custom code goes here | |
} |
```go | ||
import "github.com/Peersyst/xrpl-go/xrpl/websocket" | ||
const MyServer := "ws://localhost:6006/" | ||
client := websocket.NewClient(websocket.NewClientConfig().WithHost(MyServer)) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```go | |
import "github.com/Peersyst/xrpl-go/xrpl/websocket" | |
const MyServer := "ws://localhost:6006/" | |
client := websocket.NewClient(websocket.NewClientConfig().WithHost(MyServer)) | |
``` | |
```go | |
import "github.com/Peersyst/xrpl-go/xrpl/websocket" | |
const MY_SERVER = "ws://localhost:6006/" | |
func main() { | |
client := websocket.NewClient(websocket.NewClientConfig().WithHost(MY_SERVER)) | |
// ... custom code goes here | |
} |
|
||
## Keep on Building | ||
|
||
Now that you know how to use `xrpl.js` to connect to the XRP Ledger, get an account, and look up information about it, you can also: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you know how to use `xrpl.js` to connect to the XRP Ledger, get an account, and look up information about it, you can also: | |
Now that you know how to use `xrpl-go` to connect to the XRP Ledger, get an account, and look up information about it, you can also: |
|
||
{% code-snippet file="/_code-samples/get-tx/go/main.go" from="// Get the latest validated ledger" language="go" /%} | ||
|
||
Or use the [`websocket` or `rpc` packages](https://pkg.go.dev/github.com/Peersyst/[email protected]/xrpl/websocket#Client.GetAccountChannels) getter methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use the [`websocket` or `rpc` packages](https://pkg.go.dev/github.com/Peersyst/[email protected]/xrpl/websocket#Client.GetAccountChannels) getter methods: | |
Or, use the getter methods from the [`websocket`](https://pkg.go.dev/github.com/Peersyst/[email protected]/xrpl/websocket) or [`rpc`](https://pkg.go.dev/github.com/Peersyst/[email protected]/xrpl/rpc) packages: |
|
||
In `xrpl-go`, account creation and key management live in the wallet package, and on Testnet you can use the built-in faucet provider on your WebSocket (or RPC) client to fund a brand-new account immediately. | ||
|
||
Here we spin up a Testnet‐connected WebSocket client, generate a fresh ED25519 wallet, then fund it automatically via the public faucet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we spin up a Testnet‐connected WebSocket client, generate a fresh ED25519 wallet, then fund it automatically via the public faucet. | |
On Testnet, you can fund a new ED25519 account like this: |
client := websocket.NewClient( | ||
websocket.NewClientConfig(). | ||
WithHost("wss://s.altnet.rippletest.net:51233"). | ||
WithFaucetProvider(faucet.NewTestnetFaucetProvider()), | ||
) | ||
|
||
defer client.Disconnect() | ||
if err := client.Connect(); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client := websocket.NewClient( | |
websocket.NewClientConfig(). | |
WithHost("wss://s.altnet.rippletest.net:51233"). | |
WithFaucetProvider(faucet.NewTestnetFaucetProvider()), | |
) | |
defer client.Disconnect() | |
if err := client.Connect(); err != nil { | |
fmt.Println(err) | |
return | |
} |
We've already shown the user how to connect with the client(s) in the previous step, so we probably don't need to show this again.
fmt.Println("⏳ Autofilling flattened multi batch transaction...") | ||
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil { | ||
fmt.Println("Autofill error:", err) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use panic(err)
for all error handling in these code examples? I know it's not good practice for production code, but for documentation examples it should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Added comments and suggestions.
Add xrpl-go examples and references to xrpl-dev-portal
Description
This PR aims to include the
xrpl-go
library into the XRPLFxrpl-dev-portal
repository. Including code samples, and references to it in the documentation site.Changes
Notes
Notice that all the references to
xrpl-go
package specification and GitHub repository still points to PeerSyst's. A replace all might be done when moving the repository to XRPLF GitHub account.