Skip to content
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

feat(docs): onchain metadata creation for NFTs and Jettons #1236

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a link to the article by CertiK to Security best practices page: PR [#1185](https://github.com/tact-lang/tact/pull/1185)
- Added a note on `dump()` being computationally expensive: PR [#1189](https://github.com/tact-lang/tact/pull/1189)
- Fixed links in Chinese translation: PR [#1206](https://github.com/tact-lang/tact/pull/1206)
- Added onchain metadata creation for NFTs and Jettons to the cookbook: PR [#1236](https://github.com/tact-lang/tact/pull/1236)

### Release contributors

Expand Down
42 changes: 42 additions & 0 deletions docs/src/content/docs/cookbook/jettons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,48 @@ fun calculateJettonWalletAddress(
}
```

### Onchain metadata creation

```tact
/// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#jetton-metadata-example-offchain
fun composeJettonMetadata(
name: String, // full name
description: String, // text description of the Jetton
symbol: String, // "stock ticker" symbol without the $ prefix, like USDT or SCALE
image: String, // link to the image
// There could be other attributes, see:
novusnota marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#jetton-metadata-attributes
): Cell {
let dict: map<Int as uint256, Cell> = emptyMap();
dict.set(sha256("name"), name.asMetadataCell());
dict.set(sha256("description"), description.asMetadataCell());
dict.set(sha256("symbol"), symbol.asMetadataCell());
dict.set(sha256("image"), image.asMetadataCell());

return beginCell()
.storeUint(0, 8)
.storeBit(true)
.storeRef(dict.asCell()!!)
.endCell();
novusnota marked this conversation as resolved.
Show resolved Hide resolved
}

// Taking flight!
fun poorMansLaunchPad() {
let jettonMetadata = composeJettonMetadata(
"Best Jetton",
"A very descriptive description describing the jetton descriptively",
"JETTON",
"...link to ipfs or somewhere trusted...",
);
}

// Prefixes the String with a single null byte and converts it to a Cell
// The null byte prefix is used to express metadata in various standards, like NFT or Jetton
inline extends fun asMetadataCell(self: String): Cell {
return beginTailString().concat(self).toCell();
}
```

:::tip[Hey there!]

Didn't find your favorite example of Jetton usage? Have cool implementations in mind? [Contributions are welcome!](https://github.com/tact-lang/tact/issues)
Expand Down
80 changes: 80 additions & 0 deletions docs/src/content/docs/cookbook/nfts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,86 @@ contract Example {
}
```

## Onchain metadata creation

### NFT Collection {#onchain-metadata-nft-collection}

```tact
/// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#nft-metadata-attributes
fun composeCollectionMetadata(
name: String, // full name
description: String, // text description of the NFT
image: String, // link to the image
// There could be other attributes, see:
novusnota marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#nft-metadata-attributes
novusnota marked this conversation as resolved.
Show resolved Hide resolved
): Cell {
let dict: map<Int as uint256, Cell> = emptyMap();
dict.set(sha256("name"), name.asMetadataCell());
dict.set(sha256("description"), description.asMetadataCell());
dict.set(sha256("image"), image.asMetadataCell());

return beginCell()
.storeUint(0, 8)
.storeBit(true)
.storeRef(dict.asCell()!!)
.endCell();
}

// Taking flight!
fun poorMansLaunchPad() {
let collectionMetadata = composeCollectionMetadata(
"Best Collection",
"A very descriptive description describing the collection descriptively",
"...link to ipfs or somewhere trusted...",
);
}

// Prefixes the String with a single null byte and converts it to a Cell
// The null byte prefix is used to express metadata in various standards, like NFT or Jetton
inline extends fun asMetadataCell(self: String): Cell {
return beginTailString().concat(self).toCell();
}
```

### NFT Item {#onchain-metadata-nft-item}

```tact
/// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#nft-metadata-attributes
fun composeItemMetadata(
name: String, // full name
description: String, // text description of the NFT
image: String, // link to the image
// There could be other attributes, see:
// https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#nft-metadata-attributes
): Cell {
let dict: map<Int as uint256, Cell> = emptyMap();
dict.set(sha256("name"), name.asMetadataCell());
dict.set(sha256("description"), description.asMetadataCell());
dict.set(sha256("image"), image.asMetadataCell());

return beginCell()
.storeUint(0, 8)
.storeBit(true)
.storeRef(dict.asCell()!!)
.endCell();
}

// Taking flight!
fun poorMansLaunchPad() {
let itemMetadata = composeItemMetadata(
"Best Item",
"A very descriptive description describing the item descriptively",
"...link to ipfs or somewhere trusted...",
);
}

// Prefixes the String with a single null byte and converts it to a Cell
// The null byte prefix is used to express metadata in various standards, like NFT or Jetton
inline extends fun asMetadataCell(self: String): Cell {
return beginTailString().concat(self).toCell();
}
```

:::tip[Hey there!]

Didn't find your favorite example of a NFT communication? Have cool implementations in mind? [Contributions are welcome!](https://github.com/tact-lang/tact/issues)
Expand Down
Loading