Skip to content

Commit

Permalink
feat(docs): onchain metadata creation for NFTs and Jettons
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota committed Dec 24, 2024
1 parent 70f5a70 commit 7a81589
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
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:
// 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();
}
// 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:
// 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 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

0 comments on commit 7a81589

Please sign in to comment.