Skip to content

Commit

Permalink
Merge pull request #242 from Chia-Network/code-examples
Browse files Browse the repository at this point in the history
Initial code examples
  • Loading branch information
Rigidity authored Sep 26, 2023
2 parents d2b607e + 0c1e8aa commit d1fdb89
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/primitives/cats.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ To learn more about the terminology used on this page, check out the [blog entry

Additionally, fungible tokens can be split apart and merged together, whereas non-fungible tokens are indivisible.

## Code Examples

### chia-blockchain

The official Chia wallet has a reference implementation for the following in Python:

- [Spend CAT coins](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/cat_wallet/cat_wallet.py#L784)

### chia-rs

The wallet code used by the [MonsterSprouts example game](https://github.com/Chia-Network/MonsterSprouts) has the following reference methods:

- [Puzzle and solution types](https://github.com/Chia-Network/chia_rs/blob/wallet-dev/chia-primitives/src/primitives/cat.rs)
- [Issue new CAT](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L209)
- [Spend CAT coins](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L545)
- [Send CATs to puzzle hash](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L399)

### chia-wallet-lib

The [Chia wallet library NPM package](https://github.com/Chia-Network/node-chia-wallet-lib) has the following reference implementation:

- [Issue new CAT](https://github.com/Chia-Network/node-chia-wallet-lib/blob/6c8d564538be121079596e492fa0da497c9dd39c/src/types/puzzles/AssetToken.ts#L63)
- [Spend CAT coins](https://github.com/Chia-Network/node-chia-wallet-lib/blob/6c8d564538be121079596e492fa0da497c9dd39c/src/types/puzzles/AssetToken.ts#L102)

## CAT Code {#code}

This is the source code of the CAT, which can also be found in the chia-blockchain repository in the puzzle [`cat_v2.clvm`](https://github.com/Chia-Network/chia-blockchain/blob/fad414132e6950e79e805629427af76bf9ddcbc5/chia/wallet/puzzles/cat_v2.clvm):
Expand Down
16 changes: 16 additions & 0 deletions docs/primitives/dids.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ DIDs are a decentralized way to represent an identity, be that an organization o

More functionality will be added to the DID standard in the future, allowing for easier identification and recovery methods.

## Code Examples

### chia-blockchain

The official Chia wallet has a reference implementation for the following in Python:

- [Mint new DID](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/did_wallet/did_wallet.py#L1217)
- [Create update DID spend](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/did_wallet/did_wallet.py#L534)

### chia-rs

The wallet code used by the [MonsterSprouts example game](https://github.com/Chia-Network/MonsterSprouts) has the following reference methods:

- [Puzzle and solution types](https://github.com/Chia-Network/chia_rs/blob/wallet-dev/chia-primitives/src/primitives/did.rs)
- [Spend DID](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L1148)

## DID Code {#code}

This is the source code of the DID inner puzzle, which can also be found in the chia-blockchain repository in the puzzle [`did_innerpuz.clvm`](https://github.com/Chia-Network/chia-blockchain/blob/164fd158c8626893bc45ba00b87ae69d2ab5f8b7/chia/wallet/puzzles/did_innerpuz.clvm).
Expand Down
18 changes: 18 additions & 0 deletions docs/primitives/nfts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ NFTs are non-fungible tokens that are minted on the Chia blockchain. The NFT puz

They can be used to prove digital ownership of files such as images or videos, as well as the metadata and license pertaining to the file.

## Code Examples

### chia-blockchain

The official Chia wallet has a reference implementation for the following in Python:

- [Mint NFT](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/nft_wallet/nft_wallet.py#L321)
- [Bulk mint NFTs](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/nft_wallet/nft_wallet.py#L1242)
- [Spend NFT](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/nft_wallet/nft_wallet.py#L606)

### chia-rs

The wallet code used by the [MonsterSprouts example game](https://github.com/Chia-Network/MonsterSprouts) has the following reference methods:

- [Puzzle and solution types](https://github.com/Chia-Network/chia_rs/blob/wallet-dev/chia-primitives/src/primitives/nft.rs)
- [Bulk mint NFTs](https://github.com/Chia-Network/chia_rs/blob/wallet-dev/chia-wallet/src/wallet.rs#L665)
- [Spend NFT](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L1053).

## NFT Code {#code}

This is the source code of the NFT state layer, which can also be found in the chia-blockchain repository in the puzzle [`nft_state_layer.clvm`](https://github.com/Chia-Network/chia-blockchain/blob/164fd158c8626893bc45ba00b87ae69d2ab5f8b7/chia/wallet/puzzles/nft_state_layer.clvm).
Expand Down
14 changes: 14 additions & 0 deletions docs/primitives/offers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ slug: /offers

Offers are a way to enable peer-to-peer asset exchange on the Chia blockchain. In other words, you can swap tokens without needing to go through an exchange. Only two parties are required, the maker and the taker. They don't need to trust each other, since any attempts to modify the offer will invalidate it.

## Code Examples

### chia-blockchain

The official Chia wallet has a reference implementation for the following in Python:

- [Offer multiple assets](https://github.com/Chia-Network/chia-blockchain/blob/010cedf83718aa8e4d97da76f892fe69387a5d82/chia/wallet/trade_manager.py#L410)

### chia-rs

The wallet code used by the [MonsterSprouts example game](https://github.com/Chia-Network/MonsterSprouts) has the following reference methods:

- [Offer NFT1 for CAT2](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L101)

## Offer Files

When you create an offer, you get a string of text that is usually stored in a file. This describes the details of the trade, including the assets you are requesting and the assets you are giving in return. This file can be published on various platforms and downloaded by anyone to fulfill in the wallet of their choice. This allows for the flexibility of exchanges, while keeping it fully decentralized and preventing tampering or relying on a third party or middleman.
Expand Down
15 changes: 15 additions & 0 deletions docs/primitives/singletons.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ slug: /singletons

Singletons allow you to keep track of the state of something on the blockchain, with the ability to verify and check any part of its history using a unique id. It proves that the puzzle is unique and cannot be duplicated. Singletons can use any arbitrary inner puzzle, and is used to make NFTs, DIDs, the pooling puzzle, and many other things possible.

## Code Examples

### chia-blockchain

The official Chia wallet has a reference implementation for the following in Python:

- [Create singleton solution](https://github.com/Chia-Network/chia-blockchain/blob/e07f9196ffd8fcb6d6e7e9dc9079f2bb9bcfe464/chia/wallet/nft_wallet/nft_wallet.py#L777)

### chia-rs

The wallet code used by the [MonsterSprouts example game](https://github.com/Chia-Network/MonsterSprouts) has the following reference methods:

- [Puzzle and solution types](https://github.com/Chia-Network/chia_rs/blob/wallet-dev/chia-primitives/src/primitives/singleton.rs)
- [Create singleton solution](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L1130)

## Singleton Code {#code}

This is the source code of the singleton, which can also be found in the chia-blockchain repository in the puzzle [`singleton_top_layer_v1_1.clvm`](https://github.com/Chia-Network/chia-blockchain/blob/8b70466a70388d0fff437d138192ba38faf92be8/chia/wallet/puzzles/singleton_top_layer_v1_1.clvm).
Expand Down
21 changes: 21 additions & 0 deletions docs/primitives/standard-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ The standard transaction is a puzzle used by the Chia wallet to generate its add
Before you read this page, it may be worth checking out this [Agg Sigs, Taproot, and Graftroot blog post](https://www.chia.net/2021/05/27/Agrgregated-Sigs-Taproot-Graftroot.html) by Bram Cohen on why the standard transaction is the way it is.
:::

## Code Examples

### chia-blockchain

The official Chia wallet has a reference implementation for the following in Python:

- [Spend standard transaction](https://github.com/Chia-Network/chia-blockchain/blob/e07f9196ffd8fcb6d6e7e9dc9079f2bb9bcfe464/chia/wallet/wallet.py#L421)

### chia-rs

The wallet code used by the [MonsterSprouts example game](https://github.com/Chia-Network/MonsterSprouts) has the following reference methods:

- [Puzzle and solution types](https://github.com/Chia-Network/chia_rs/blob/wallet-dev/chia-primitives/src/primitives/standard_puzzle.rs)
- [Spend standard transaction](https://github.com/Chia-Network/chia_rs/blob/2334c842f694444da317fa7432f308f159f62d70/chia-wallet/src/wallet.rs#L1166)

### chia-wallet-lib

The [Chia wallet library NPM package](https://github.com/Chia-Network/node-chia-wallet-lib) has the following reference implementation:

- [Spend standard transaction](https://github.com/Chia-Network/node-chia-wallet-lib/blob/6c8d564538be121079596e492fa0da497c9dd39c/src/types/puzzles/StandardTransaction.ts#L27)

## Terminology

**Hidden Puzzle** -
Expand Down

0 comments on commit d1fdb89

Please sign in to comment.