1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge 726e34c8fc013523d7db6bad7a86687c9a462f2d into 94fd276d6b34b3e4d620871d06e7e23271be6868

This commit is contained in:
Jamie Hewitt 2022-12-21 15:06:30 +00:00 committed by GitHub
commit 3e03432e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 0 deletions

View File

@ -677,6 +677,49 @@ Let's check we received the download URL ok
``` ```
### 8.1 Add key-value pair to data NFT
Data NFTs can store arbitrary key-value pairs on-chain. This opens up their usage for a broad variety of applications, such as comments & ratings, attestations, and privately sharing data (when the value is encrypted).
Let's see how!
Here are the steps:
1. Setup (same as above)
2. Publish data NFT (same as above)
3. Add key-value pair to data NFT (use the `setData` method)
4. Retrieve value from data NFT (use the `getData` method)
Let's start by using the `setData` method to update the nft key value store with some data
```Typescript
const nft = new Nft(web3)
const data = 'SomeData'
try {
await nft.setData(freNftAddress, publisherAccount, '1', data)
} catch (e) {
console.error(e)
assert.fail('Download failed')
}
```
Under the hood, this uses [ERC725](https://erc725alliance.org/), which augments ERC721 with a well-defined way to set and get key-value pairs.
### 8.2 Add key-value pair to data NFT
```Typescript
const nft = new Nft(web3)
try {
Use the `getData` method to get the data stored in the nft key value store
const data = await nft.getData(freNftAddress, '1')
console.log('Data: ', data)
} catch (e) {
console.error(e)
assert.fail('Download failed')
}
```
That's it! Note the simplicity. All data was stored and retrieved from on-chain. We don't need Ocean Provider or Ocean Aquarius for these use cases (though the latter can help for fast querying & retrieval).
## Editing this file ## Editing this file
Please note that CodeExamples.md is an autogenerated file, you should not edit it directly. Please note that CodeExamples.md is an autogenerated file, you should not edit it directly.

View File

@ -31,6 +31,7 @@
"test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'", "test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
"test:unit:cover": "nyc --report-dir coverage/unit --exclude 'src/@types/**/*' npm run test:unit", "test:unit:cover": "nyc --report-dir coverage/unit --exclude 'src/@types/**/*' npm run test:unit",
"test:integration": "npm run mocha -- 'test/integration/**/*.test.ts'", "test:integration": "npm run mocha -- 'test/integration/**/*.test.ts'",
"test:guide": "npm run mocha -- 'test/integration/CodeExamples.test.ts'",
"test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration", "test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
"create:guide": "./scripts/createCodeExamples.sh test/integration/CodeExamples.test.ts", "create:guide": "./scripts/createCodeExamples.sh test/integration/CodeExamples.test.ts",
"create:guidec2d": "./scripts/createCodeExamples.sh test/integration/ComputeExamples.test.ts", "create:guidec2d": "./scripts/createCodeExamples.sh test/integration/ComputeExamples.test.ts",

View File

@ -676,6 +676,49 @@ describe('Marketplace flow tests', async () => {
} }
}) /// }) ///
/// ``` /// ```
it('8.1 Add key-value pair to data NFT', async () => {
/// Data NFTs can store arbitrary key-value pairs on-chain. This opens up their usage for a broad variety of applications, such as comments & ratings, attestations, and privately sharing data (when the value is encrypted).
/// Let's see how!
/// Here are the steps:
/// 1. Setup (same as above)
/// 2. Publish data NFT (same as above)
/// 3. Add key-value pair to data NFT (use the `setData` method)
/// 4. Retrieve value from data NFT (use the `getData` method)
/// Let's start by using the `setData` method to update the nft key value store with some data
/// ```Typescript
const nft = new Nft(web3)
const data = 'SomeData'
try {
await nft.setData(freNftAddress, publisherAccount, '1', data)
} catch (e) {
console.error(e)
assert.fail('Download failed')
}
/// ```
/// Under the hood, this uses [ERC725](https://erc725alliance.org/), which augments ERC721 with a well-defined way to set and get key-value pairs.
}) ///
it('8.2 get the key-value pair data from the NFT', async () => {
/// ```Typescript
const nft = new Nft(web3)
try {
/// Use the `getData` method to get the data stored in the nft key value store
const data = await nft.getData(freNftAddress, '1')
console.log('Data: ', data)
} catch (e) {
console.error(e)
assert.fail('Download failed')
}
/// ```
/// That's it! Note the simplicity. All data was stored and retrieved from on-chain. We don't need Ocean Provider or Ocean Aquarius for these use cases (though the latter can help for fast querying & retrieval).
}) ///
}) /// }) ///
/// ## Editing this file /// ## Editing this file