Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ displayed_sidebar: clearnetSidebar
[Git Source](https://github.com/layer-3/yellow/blob/11ed85c3dabaaddeee431052032791a80eaf2a0e/src/AppRegistry.sol)

**Inherits:**
[Locker](/src/Locker.sol/abstract.Locker.md), [ISlash](/src/interfaces/ISlash.sol/interface.ISlash.md), AccessControl
[Locker](./locker), [ISlash](./interfaces/islash), AccessControl

**Title:**
AppRegistry
Expand Down Expand Up @@ -146,4 +146,3 @@ event MinSlashAmountUpdated(uint256 oldAmount, uint256 newAmount);
```solidity
error SlashCooldownActive(uint256 availableAt);
```

3 changes: 1 addition & 2 deletions docs/clearnet/learn/contracts/api-reference/locker.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ displayed_sidebar: clearnetSidebar
[Git Source](https://github.com/layer-3/yellow/blob/11ed85c3dabaaddeee431052032791a80eaf2a0e/src/Locker.sol)

**Inherits:**
[ILock](/src/interfaces/ILock.sol/interface.ILock.md), ReentrancyGuard
[ILock](./interfaces/ilock), ReentrancyGuard

**Title:**
Locker
Expand Down Expand Up @@ -167,4 +167,3 @@ Hook called after relock. Override to add custom logic.
```solidity
function _afterRelock(address account, uint256 balance) internal virtual;
```

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ displayed_sidebar: clearnetSidebar
[Git Source](https://github.com/layer-3/yellow/blob/11ed85c3dabaaddeee431052032791a80eaf2a0e/src/NodeRegistry.sol)

**Inherits:**
[Locker](/src/Locker.sol/abstract.Locker.md), Votes
[Locker](./locker), Votes

**Title:**
NodeRegistry
Expand Down Expand Up @@ -60,4 +60,3 @@ Returns the locked collateral as weight units for the OZ Votes system.
```solidity
function _getVotingUnits(address account) internal view override returns (uint256);
```

2 changes: 1 addition & 1 deletion docs/clearnet/learn/contracts/sdk/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ type ContractAddresses = {

### Current Addresses

See [Deployed Addresses](../operations/addresses.md) for the full list.
See [Deployed Addresses](../index.md) for the full list.
17 changes: 3 additions & 14 deletions docs/nitrolite/build/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ Stack and SDK details reflect the linked repositories when this page was added.
<h2>Co-Sign Checkout</h2>
</div>
<div className="card__body">
<p className="nitrolite-example-card__summary">
A shared checkout demo where two participants create a cart, co-sign checkout actions,
move funds into an app-session cart, propose purchases, close the cart, and withdraw
remaining shared-wallet funds.
</p>
<p className="nitrolite-example-card__summary">A shared checkout demo where two participants create a cart, co-sign checkout actions, move funds into an app-session cart, propose purchases, close the cart, and withdraw remaining shared-wallet funds.</p>
<div className="nitrolite-example-card__details">
<div>
<h3>Functionality</h3>
Expand Down Expand Up @@ -74,11 +70,7 @@ Stack and SDK details reflect the linked repositories when this page was added.
<h2>Nitrolite Store</h2>
</div>
<div className="card__body">
<p className="nitrolite-example-card__summary">
A content-store reference app with a Go backend and browser frontend. The shopper connects
MetaMask, opens a store app session, adds funds, buys catalog content, reads purchased
content, and withdraws the remaining balance.
</p>
<p className="nitrolite-example-card__summary">A content-store reference app with a Go backend and browser frontend. The shopper connects MetaMask, opens a store app session, adds funds, buys catalog content, reads purchased content, and withdraws the remaining balance.</p>
<div className="nitrolite-example-card__details">
<div>
<h3>Functionality</h3>
Expand Down Expand Up @@ -125,10 +117,7 @@ Stack and SDK details reflect the linked repositories when this page was added.
<h2>Nexus P2P Transfer</h2>
</div>
<div className="card__body">
<p className="nitrolite-example-card__summary">
A workshop-style content app that demonstrates wallet connection, Nitrolite session setup,
balance polling, and instant peer-to-peer support payments to post authors.
</p>
<p className="nitrolite-example-card__summary">A workshop-style content app that demonstrates wallet connection, Nitrolite session setup, balance polling, and instant peer-to-peer support payments to post authors.</p>
<div className="nitrolite-example-card__details">
<div>
<h3>Functionality</h3>
Expand Down
4 changes: 2 additions & 2 deletions docs/nitrolite/build/getting-started/prerequisites.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ node dist/scripts/create-wallet.js

### Get Test Tokens

<!-- coming soon: faucet endpoint pending
{/* coming soon: faucet endpoint pending

```bash
curl -XPOST https://clearnet-sandbox.yellow.com/faucet/requestTokens \
-H "Content-Type: application/json" \
-d '{"userAddress":"<your_wallet_address>"}'
```

-->
*/}

If you need on-chain gas or token balances before the sandbox faucet is pinned, use the relevant testnet faucet for your chain and RPC endpoint.

Expand Down
142 changes: 65 additions & 77 deletions docs/nitrolite/build/sdk/go/api-reference.mdx
Original file line number Diff line number Diff line change
@@ -1,86 +1,79 @@
---
title: API Reference
description: Complete API reference for the Nitronode Go SDK
description: Complete API reference for the Nitrolite Go SDK
sidebar_position: 2
---

# Go SDK API Reference

## State Operations (Off-Chain)
The Go SDK package is `github.com/layer-3/nitrolite/sdk/go`. It wraps Nitronode v1 RPC methods and ChannelHub settlement helpers in typed Go methods.

```go
client.Deposit(ctx, blockchainID, asset, amount) // Prepare deposit state
client.Withdraw(ctx, blockchainID, asset, amount) // Prepare withdrawal state
client.Transfer(ctx, recipientWallet, asset, amount) // Prepare transfer state
client.CloseHomeChannel(ctx, asset) // Prepare finalize state
client.Acknowledge(ctx, asset) // Acknowledge received state
```

All return `(*core.State, error)`. Use `Checkpoint` to settle on-chain.
## App-Builder Methods

---
These are the methods most builders use in normal applications.

## Blockchain Settlement
### Channel State

```go
client.Checkpoint(ctx, asset) // Settle latest state on-chain
client.Challenge(ctx, state) // Submit on-chain challenge
client.ApproveToken(ctx, chainID, asset, amount) // Approve ChannelHub to spend tokens
client.GetOnChainBalance(ctx, chainID, asset, wallet) // Query on-chain token balance
client.Deposit(ctx, blockchainID, asset, amount) // (*core.State, error)
client.Withdraw(ctx, blockchainID, asset, amount) // (*core.State, error)
client.Transfer(ctx, recipientWallet, asset, amount) // (*core.State, error)
client.CloseHomeChannel(ctx, asset) // (*core.State, error)
client.Acknowledge(ctx, asset) // (*core.State, error)
```

`Checkpoint` routes automatically based on transition type and channel status:
- **Void** → creates channel
- **Deposit/Withdrawal** → checkpoints state
- **Finalize** → closes channel

---
Use `Checkpoint` when the latest prepared state needs on-chain settlement.

## Node Information
### Settlement

```go
client.Ping(ctx) // Health check
client.GetConfig(ctx) // Node configuration
client.GetBlockchains(ctx) // Supported blockchains
client.GetAssets(ctx, &blockchainID) // Supported assets (nil for all)
client.Checkpoint(ctx, asset) // (string, error)
client.Challenge(ctx, state) // (string, error)
client.ApproveToken(ctx, chainID, asset, amount) // (string, error)
client.GetOnChainBalance(ctx, chainID, asset, wallet) // (decimal.Decimal, error)
```

---
`Checkpoint` routes by transition type and channel status:

| Latest state | Effect |
| --- | --- |
| Void channel plus deposit state | Creates the channel and locks funds. |
| Deposit or withdrawal state | Checkpoints and applies the fund movement. |
| Finalize state | Closes the channel. |

## User Queries
### Node and Asset Discovery

```go
client.GetBalances(ctx, wallet) // User balances
client.GetTransactions(ctx, wallet, opts) // Transaction history (paginated)
client.Ping(ctx)
client.GetConfig(ctx)
client.GetBlockchains(ctx)
client.GetAssets(ctx, &blockchainID)
client.SetHomeBlockchain(asset, chainID)
```

---

## Channel Queries
### User and Channel Queries

```go
client.GetHomeChannel(ctx, wallet, asset) // Home channel info
client.GetEscrowChannel(ctx, escrowChannelID) // Escrow channel info
client.GetLatestState(ctx, wallet, asset, onlySigned) // Latest state
client.GetBalances(ctx, wallet)
client.GetTransactions(ctx, wallet, opts)
client.GetHomeChannel(ctx, wallet, asset)
client.GetEscrowChannel(ctx, escrowChannelID)
client.GetLatestState(ctx, wallet, asset, onlySigned)
```

---
`GetEscrowChannel` is a query helper. Escrow operation guides are not public app-builder docs yet.

## App Registry
## App Registry and Sessions

```go
apps, meta, err := client.GetApps(ctx, &sdk.GetAppsOptions{
AppID: &appID,
OwnerWallet: &wallet,
})

err := client.RegisterApp(ctx, "my-app", `{"name": "My App"}`, false)
err := client.RegisterApp(ctx, "my-app", `{"name":"My App"}`, false)
```

---

## App Sessions

```go
sessions, meta, err := client.GetAppSessions(ctx, opts)
def, err := client.GetAppDefinition(ctx, appSessionID)
Expand All @@ -90,9 +83,11 @@ err := client.SubmitAppState(ctx, update, sigs)
batchID, err := client.RebalanceAppSessions(ctx, signedUpdates)
```

---
Apps are responsible for collecting quorum signatures before calling `CreateAppSession`, `SubmitAppSessionDeposit`, or `SubmitAppState`.

## Session Keys: App Sessions
## Session Keys

### App Sessions

```go
state := app.AppSessionKeyStateV1{
Expand All @@ -103,63 +98,56 @@ state := app.AppSessionKeyStateV1{
AppSessionIDs: []string{},
ExpiresAt: time.Now().Add(24 * time.Hour),
}

sig, err := client.SignSessionKeyState(state)
state.UserSig = sig
err = client.SubmitAppSessionKeyState(ctx, state)

states, err := client.GetLastAppKeyStates(ctx, userAddress, nil)
```

---

## Session Keys: Channels
### Channels

```go
state := core.ChannelSessionKeyStateV1{
UserAddress: client.GetUserAddress(),
SessionKey: "0xSessionKey...",
Version: 1,
Assets: []string{"usdc", "weth"},
Assets: []string{"yellow"},
ExpiresAt: time.Now().Add(24 * time.Hour),
}

sig, err := client.SignChannelSessionKeyState(state)
state.UserSig = sig
err = client.SubmitChannelSessionKeyState(ctx, state)

states, err := client.GetLastChannelKeyStates(ctx, userAddress, nil)
```

---

## Utilities

```go
client.Close() // Close connection
client.WaitCh() // Connection monitor channel
client.SignState(state) // Sign a state (advanced)
client.GetUserAddress() // Get signer's address
client.SetHomeBlockchain(asset, chainID) // Set default blockchain
client.Close()
client.WaitCh()
client.SignState(state)
client.GetUserAddress()
```

---

## Types
## Common Types

```go
// Core types
core.State // Channel state
core.Channel // Channel info
core.Transition // State transition
core.Transaction // Transaction record
core.Asset // Asset info
core.Blockchain // Blockchain info
core.ChannelSessionKeyStateV1 // Channel session key state

// App types
app.AppV1 // Application definition
app.AppInfoV1 // Application info with timestamps
app.AppSessionInfoV1 // Session info
app.AppDefinitionV1 // Session definition
app.AppStateUpdateV1 // Session update
app.AppSessionKeyStateV1 // App session key state
core.State
core.Channel
core.Transition
core.Transaction
core.Asset
core.Blockchain
core.ChannelSessionKeyStateV1

app.AppV1
app.AppInfoV1
app.AppSessionInfoV1
app.AppDefinitionV1
app.AppStateUpdateV1
app.AppSessionKeyStateV1
```
66 changes: 66 additions & 0 deletions docs/nitrolite/build/sdk/go/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Examples
description: Go SDK examples for channels and app sessions
sidebar_position: 3
---

# Go SDK Examples

Use these examples as starting points for backend services and CLIs that call Nitronode with `github.com/layer-3/nitrolite/sdk/go`.

## Channel Funding and Transfer

```go
ctx := context.Background()
chainID := uint64(11155111)
asset := "yellow"
amount := decimal.NewFromFloat(0.01)

if err := client.SetHomeBlockchain(asset, chainID); err != nil {
return err
}

if _, err := client.ApproveToken(ctx, chainID, asset, amount); err != nil {
return err
}

if _, err := client.Deposit(ctx, chainID, asset, amount); err != nil {
return err
}

if _, err := client.Checkpoint(ctx, asset); err != nil {
return err
}

if _, err := client.Transfer(ctx, "0xRecipient...", asset, decimal.NewFromFloat(0.001)); err != nil {
return err
}
```

## App Session Update

```go
update := app.AppStateUpdateV1{
AppSessionID: appSessionID,
Version: 2,
Intent: app.AppStateUpdateIntentOperate,
Allocations: allocations,
SessionData: `{"purchase":"content-1"}`,
}

// The application gathers quorum signatures before submitting.
if err := client.SubmitAppState(ctx, update, quorumSigs); err != nil {
return err
}
```

## Query Latest State

```go
state, err := client.GetLatestState(ctx, client.GetUserAddress(), "yellow", true)
if err != nil {
return err
}

fmt.Printf("version=%d transition=%s\n", state.Version, state.Transition.Type)
```
Loading
Loading