Skip to content

Commit

Permalink
Merge pull request #201 from linnnsss/update_SDK_examples
Browse files Browse the repository at this point in the history
Update sdk examples (in rust, go, java, JS)
  • Loading branch information
jordanmack authored Oct 24, 2023
2 parents 65b3d96 + 9c81a32 commit acdb234
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 103 deletions.
39 changes: 39 additions & 0 deletions website/docs/basics/guides/SDK_examples/go_lang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: sdk_examples_go
title: Go
sidebar_position: 3
---

import useBaseUrl from "@docusaurus/useBaseUrl";

import Link from "@docusaurus/Link";

## Single-sig transfer

- With [Secp256k1](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L21-L60)
- With [Omnilock](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L408-L460)
- With [Light-client](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L62)

## Multi-sig transfer

- With [Secp256k1](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L114)
- With [Omnilock](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L462)

## Chained transfer

- [Chained transfer](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L529)

## Issue and send SUDT

- [Issue](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L176)

- [Send](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L220)

## DAO Deposit

- [Deposit](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L264)

## DAO Withdrawal

- [Withdraw](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L304)
- [Claim](https://github.com/nervosnetwork/ckb-sdk-go/blob/4f43fd577e215b746e2c55b65fa7df2085e58c83/collector/example/example.go#L357)
39 changes: 39 additions & 0 deletions website/docs/basics/guides/SDK_examples/java_lang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: sdk_examples_java
title: Java
sidebar_position: 4
---

import useBaseUrl from "@docusaurus/useBaseUrl";

import Link from "@docusaurus/Link";

## Single-sig transfer

- With [Secp256k1](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/SendCkbExample.java)
- With [Omnilock](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/OmnilockExample.java)
- With [Light-client](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/SendCkbByLightClientExample.java)

## Multi-sig transfer

- With [Secp256k1](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/SendCkbMultisigExample.java)
- With [Omnilock](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/OmnilockMultisigExample.java)

## Chained transfer

- [Chained transfer](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/SendChainedTransactionExample.java)

## Issue and send SUDT

- [Issue](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/IssueSudtExample.java)

- [Send](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/SendSudtExample.java)

## DAO Deposit

- [Deposit](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/DaoDepositExample.java)

## DAO Withdrawal

- [Withdraw](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/DaoWithdrawExample.java)
- [Claim](https://github.com/nervosnetwork/ckb-sdk-java/blob/master/example/src/main/java/org/nervos/ckb/example/DaoClaimExample.java)
21 changes: 21 additions & 0 deletions website/docs/basics/guides/SDK_examples/lumos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
id: sdk_examples_lumos
title: Lumos/Javascript
sidebar_position: 5
---
Lumos is a full-featured JavaScript/TypeScript based dapp framework. [This tutorial](https://github.com/homura/hello-lumos/tree/develop/tutorial) covers a range of actions from initializing your environment to more advanced tasks like issuing and transferring SUDT.

## Single-sig transfer

- With [secp256k1](https://github.com/homura/hello-lumos/blob/ee3b9c10b425caca0787e20774274c28dbfe2256/tutorial/04-transfer-alice-ckb-to-bob.ts).

## Issue and send SUDT

- [Issue](https://github.com/homura/hello-lumos/blob/develop/tutorial/05-issue-sudt-from-alice.ts)
- [Send](https://github.com/homura/hello-lumos/blob/develop/tutorial/06-transfer-sudt-from-alice-to-bob.ts)

## DAO operations

You can find the code examples related to the Nervos DAO, covering the three primary operations of [depositing](https://github.com/homura/hello-lumos/blob/ee3b9c10b425caca0787e20774274c28dbfe2256/dao-tutorial/01-dao.ts#L47-L70), [withdrawing](https://github.com/homura/hello-lumos/blob/ee3b9c10b425caca0787e20774274c28dbfe2256/dao-tutorial/01-dao.ts#L72-L96), and [unlocking assets](https://github.com/homura/hello-lumos/blob/ee3b9c10b425caca0787e20774274c28dbfe2256/dao-tutorial/01-dao.ts#L98-L130) on CKB testnet by following [this](https://github.com/homura/hello-lumos/blob/develop/dao-tutorial/01-dao.ts) GitHub link.

For a local development environment, you can refer to [this](https://github.com/homura/hello-lumos/blob/ee3b9c10b425caca0787e20774274c28dbfe2256/dao-tutorial/02-local-dao.ts) link instead.
48 changes: 48 additions & 0 deletions website/docs/basics/guides/SDK_examples/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
id: sdk_examples_overview
title: Overview
sidebar_position: 1
---

import useBaseUrl from "@docusaurus/useBaseUrl";

import Link from "@docusaurus/Link";

The current SDK examples, available for Rust, Go, Java, and JavaScript, provide the three most common scenarios for managing your assets:

## Native CKB Transfers
1. Single-sig transfer with secp256k1 and Omnilock

Sign and send CKB from a single-sig address.

2. Single-sig transfer using [`ckb-light-client`](https://github.com/nervosnetwork/ckb-light-client) with secp256k1

Transfer from a single-sig addresses with enhanced efficiency.

3. Multi-sig transfer with secp256k1 and Omnilock

Sign and send CKB with multiple private keys.

4. Chained transfer with secp256k1

By using the previous transaction's output as the next one's input, chain transfer allows the construction of new transactions with unconfirmed on-chain inputs, reducing waiting time and enhancing efficiency.

## SUDT Transfers
SUDT (Simple User Defined Tokens) is a token standard on CKB that enables the creation and transfer of custom tokens. For more information, see [RFC 0025 Simple UDT](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0025-simple-udt/0025-simple-udt.md).

1. SUDT issuance
2. SUDT transfer

## Nervos DAO-Related Operations
Nervos DAO is a CKB smart contract that provides secondary rewards for CKByte deposits, to safeguard holders from dilution. Deposits in NervosDAO are subject to a minimum lockup period, and withdrawals are only possible once the lockup period elapses. For more information, see [RFC 0023 Deposit and Withdraw in Nervos DAO](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md).
1. Deposit

Deposit CKB into Nervos DAO.

2. Withdrawal-1 withdraw

Transform a deposit cell into a withdrawl cell.

3. Withdrawal-2 claim

Claim the transformed cell after a mandatory lockup period following the deposit transaction.
45 changes: 45 additions & 0 deletions website/docs/basics/guides/SDK_examples/rust_lang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
id: sdk_examples_rust
title: Rust
sidebar_position: 2
---

import useBaseUrl from "@docusaurus/useBaseUrl";

import Link from "@docusaurus/Link";

## Single-sig transfer

* With [Secp256k1](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/send_ckb_example.rs)

* With [Omnilock](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/transfer_from_omnilock.rs)


## Multi-sig transfer

* [1-of-2 multisig](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/send_ckb_multisig_example.rs) with Secp256k1 (one of two private keys required)

* [2-of-2 multisig](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/transfer_from_multisig.rs
) with Secp256k1 (both private keys required)

* With [Omnilock](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/transfer_from_omnilock_multisig.rs)

## Chained transfer

* [Chained transfer](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/chain_transfer_sighash.rs)

## Issue and send SUDT

* [Issue](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/sudt_issue.rs)

* [Send](https://github.com/nervosnetwork/ckb-sdk-rust/blob/master/examples/sudt_send.rs)

## DAO Deposit

* [Deposit](https://github.com/nervosnetwork/ckb-sdk-rust/pull/70/commits/25a470f7219a6ed0fab55e055a145559813c1628)

### DAO Withdrawal

* [Withdraw](https://github.com/nervosnetwork/ckb-sdk-rust/pull/70/commits/4c24fca4cae40fc57d2258449b69f2fd189ed623#diff-edd624119e43a07b0e85b9517a1d3544ebe002215b31ec91700d603843bb434e)

* [Claim](https://github.com/nervosnetwork/ckb-sdk-rust/pull/70/commits/dae479a751fd2c3a4991da11abd5c2076e45b735#diff-d461964487b262c57f8bdf4a2845d3e6c4dc449c2573165f1f03618e173f63c1)
22 changes: 13 additions & 9 deletions website/docs/integrate/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ id: sdk
title: Nervos CKB SDK
---

ckb-sdk is a collection of libraries which allow you to interact with a local or remote CKB node by using JSON-RPC. You should get familiar with [ckb transaction structure](reference/transaction.md) and [JSON-RPC](https://github.com/nervosnetwork/ckb/tree/develop/rpc) before using it. Now ckb-sdk is implemented by the following programming languages: JavaScript/TypeScript,Ruby,Swift,Java and Go.
ckb-sdk is a collection of libraries which allow you to interact with a local or remote CKB node by using JSON-RPC. You should get familiar with [ckb transaction structure](reference/transaction.md) and [JSON-RPC](https://github.com/nervosnetwork/ckb/tree/develop/rpc) before using it. Now ckb-sdk is implemented by the following programming languages: Rust, JavaScript/TypeScript, Go, Java, Ruby, and Swift.

* [ckb-sdk-rust](https://github.com/nervosnetwork/ckb-sdk-rust)
* ckb-sdk-rust is an SDK implemented in Rust. [This page](https://github.com/nervosnetwork/ckb-sdk-rust/tree/master/examples) provides the code examples for single- and multi-sig transfers, SUDT and Nervos DAO-related operations.

* [Lumos](https://github.com/ckb-js/lumos)
* Lumos is a JavaScript/TypeScript framework designed to make backend Dapp development on Nervos CKB easier.
Visit the [Lumos Tutorial Page](https://lumos-website.vercel.app/) for more instructions and step-by-step guidance.
* Lumos is a JavaScript/TypeScript framework designed to make backend Dapp development on Nervos CKB easier. [This tutorial](https://github.com/homura/hello-lumos/tree/develop/tutorial) covers a range of actions from initializing your environment to more advanced tasks like issuing and transferring SUDT. Also visit the [Lumos Tutorial Page](https://lumos-website.vercel.app/) for more instructions and step-by-step guidance.

* [ckb-sdk-go](https://github.com/nervosnetwork/ckb-sdk-go)
* ckb-sdk-go is an SDK implemented in Golang. [This page](https://github.com/nervosnetwork/ckb-sdk-go/tree/v2/collector/example) provides the code examples for single- and multi-sig transfers, SUDT and Nervos DAO-related operations.

* [ckb-sdk-java](https://github.com/nervosnetwork/ckb-sdk-java)
* ckb-sdk-java is an SDK implemented in Java. [This page](https://github.com/nervosnetwork/ckb-sdk-java/tree/master/example) provides the code examples for single- and multi-sig transfers, SUDT and Nervos DAO-related operations.

* [ckb-sdk-ruby](https://github.com/nervosnetwork/ckb-sdk-ruby)
* ckb-sdk-ruby is an SDK implemented in Ruby and provides APIs for developers to send requests to the CKB blockchain. CKB-Explorer and Testnet Faucet utilize ckb-sdk-ruby.
* [ckb-sdk-java](https://github.com/nervosnetwork/ckb-sdk-java)
* ckb-sdk-java is an SDK implemented in Java and provides APIs for developers to send requests to the CKB blockchain.

* [ckb-sdk-swift](https://github.com/ashchan/ckb-swift-kit)
* ckb-sdk-swift is an SDK implemented in Swift and provides APIs for developers to send requests to the CKB blockchain.
* [ckb-sdk-go](https://github.com/nervosnetwork/ckb-sdk-go)
* ckb-sdk-go is an SDK implemented in Golang.
* [ckb-sdk-rust](https://github.com/nervosnetwork/ckb-sdk-rust)
* ckb-sdk-rust is an SDK implemented in Rust.
Loading

0 comments on commit acdb234

Please sign in to comment.