Skip to content

Commit

Permalink
Merge branch 'main' of github.com:nevermined-io/app_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aaitor committed Mar 1, 2024
2 parents 3c0f3cf + e062a34 commit caabd2b
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 31 deletions.
44 changes: 14 additions & 30 deletions docs/getting-started/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,32 @@ description: FAQ

## What is Nevermined?

Nevermined brings together Data and AI to develop next generation services for developers.
One of the standout features of Nevermined is the full data & AI provenance tracking. This grants users full transparency over the sources AI is accessing when replying to prompts and sets the infrastructure for rewarding the data publishers.
Nevermined is the AI payments protocol delivering the Web3 standard for AI-to-AI transactions. At Nevermined, we AI payments are a protocol, not a feature, and we're building the Open Source software to power AI's future.

## What is Nevermined App?

The Nevermined App allows Data & AI developers to create tokenized subscriptions that allow them to monetize their data assets or web services. These Smart Subscriptions simply create access tokens according to the time and price conditions set by the publisher. This smart contract then tokengates your assets for a set period of time to wallets that own the access token. No Smart Subscription token = No Access.
The Nevermined App allows AI builders to monetize their AI agents and associated assets, like context data, etc. You do this by creating a Smart Subscription in which you specify the access parameters to your AI agent, such as price, time limit, and/or number of requests that can be made to use your AI agent. You then add your AI agent API to the subscription, and make the AI available to your users.

## Who can use Nevermined App?

### Publishers
### AI Builders

AI Owners can use Nevermined to tokenize the Web Service of their AI model or agent by defining access conditions and making it available to app developers who want to integrate AI services into their product, but don’t want to build it from scratch.

Data Owners can use Nevermined to tokenize data sets or services, set pricing and access control conditions and then make it available to AI builders to train their models.
You can use Nevermined to tokenize datasets or services, set pricing and access control conditions and then make it available to AI builders to train their models.

### Consumers
### AI Users

AI developers can use Nevermined to purchase access to datasets that are relevant to their model.
AI users can use Nevermined to purchase access to datasets that are relevant to their model.

App developers can purchase access to a broad range of AI Services and integrate them into their product, so they don’t need to build AI services from scratch.

Researchers or data consumers who require access to specific or specialized data that is not readily accessible to the public, can purchase access to datasets, in order to advance their research.

## How does Nevermined App work?

* AI service publishers can tokenize their API endpoint and embed time and price access conditions. Data publishers will simply go through an upload flow.
* Once the subscription terms are created, a DID associated with the publisher’s wallet is issued and it can be then linked to a specific subscription.
* At the end of the process, the App will automatically create a widget containing the subscription information and display it on the marketplace, but publishers also have the option to embed this widget on their own point-of-sale, i.e. website or channel.
* Purchasing access means the asset's smart contract sends the buyer a non-fungible Subscription token, using ERC-standards, that can be simply copied into the Buyer’s application.
* AI agent / service builders can monetize their API endpoint and embed time and price access conditions.
* Once the subscription terms are created, a DID associated with the builder’s wallet is issued and it can be then linked to a specific subscription.
* At the end of the process, the App will automatically create a widget containing the subscription information and display it on the marketplace, but builders also have the option to embed this widget on their own point-of-sale, i.e. website or channel.
* Purchasing access means the asset's smart contract sends the buyer a non-fungible Subscription token, using ERC-standards, that can be simply copied into the users' application.
* This Smart Subscription proves ownership of a unique JWT access token, which allows the user to send HTTP requests to the AI's web service

## What are Smart Subscriptions
Expand All @@ -56,27 +53,18 @@ The result? Much greater usability and a big step change in overall utility.

Web services allow applications to interact with each other over the internet, enabling data exchange, communication, and functionality.

## What do I need to get started as an AI Services Publisher?
## What do I need to get started as an AI Agent Builder?

* A Metamask wallet;
* If you publish your assets on Polygon, you need MATIC tokens to pay for the gas fees on that network;
* If you publish your assets on Gnosis, you need xDAI to pay for the gas fees on that network;
* If you publish your assets on Arbitrum, you need Arbitrum ETH to pay for the gas fees on that network;
* Your assets: Server link and authentication token.
* Standard Contract for Marketplace (SCMP) agreement that will govern the usage of your asset. You have the option to utilize the default Nevermined Standard Contract but we strongly encourage Publishers to apply their own SCMP.
* Standard Contract for Marketplace (SCMP) agreement that will govern the usage of your asset. You have the option to utilize the default Nevermined Standard Contract but we strongly encourage Builders to apply their own SCMP.

## What do I need to get started as a Data Publisher?
## What do I need to get started as a user?

* A Metamask wallet;
* If you publish your assets on Polygon, you need MATIC tokens to pay for the gas fees on that network;
* If you publish your assets on Gnosis, you need xDAI to pay for the gas fees on that network;
* If you publish your assets on Arbitrum, you need Arbitrum ETH to pay for the gas fees on that network;
* Your data assets. All file formats are supported. Max file size: 50 MB;
* End user license agreement (EULA) that will govern the usage of your asset. You have the option to utilize the default Nevermined Standard Contract but we strongly encourage Publishers to apply their own EULA.

## What do I need to get started as a consumer?

* A wallet;
* An account which is linked to a wallet (don't worry, Nevermined can handle the wallet part);
* If you’re buying an asset on [Polygon Network](https://matic.nevermined.app/), you need USDC tokens to pay for the assets you want to purchase and a small amount of MATIC for the network gas fees.
* If you’re buying an asset on [Gnosis Network](https://gnosis.nevermined.app/), you need USDC tokens to pay for the assets you want to purchase and a small amount of xDAI for the network gas fees.
* If you’re buying an asset on [Arbitrum](https://nevermined.app/), you need USDC tokens to pay for the assets you want to purchase and a small amount of MATIC for the network gas fees.
Expand Down Expand Up @@ -124,7 +112,3 @@ At the moment, the Nevermined App is deployed on the Polygon, Gnosis and Arbitru
## How do I claim back my locked tokens if a transaction fails during processing?

In order to claim payment tokens that get locked during a failed transaction, you need the agreementID for the transaction. This agreementID is displayed in the Nevermined App with a failure message in the case that the transaction fails. In the event of a transaction failure, please record the agreementID and then contact Nevermined App Support via the [Nevermined Discord](https://discord.com/invite/GZju2qScKq) Support channel.

## What is a Data Schema?

A database schema is the skeleton structure that represents the logical view of the entire database. It defines how the data is organized and how the relations among them are associated. It formulates all the constraints that are to be applied on the data.
175 changes: 175 additions & 0 deletions docs/tutorials/integration/nextjs-react-payments.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
---
sidebar_position: 3
description: How to integrate the Nevermined Payments library in a react application
---

import PaymentsTutorial from '@site/src/components/payments/tutorial'

# Tutorial on how to use the Nevermined Payments Protocol in a React app

### Initializing the project

For this tutorial we will be using [nextjs](https://nextjs.org/docs/getting-started/installation)
create our react application.

1. Initialize the react project

```
npx create-next-app@latest
```

2. Install the Nevermined [payments library](https://github.com/nevermined-io/payments)

```
yarn add @nevermined-io/payments
```

3. Starting the development server

```
yarn dev
```

### Initialize the payments library

In order to initialize the payments library we need to have the user login to Nevermined. This can
be achieved by calling the `connect` method that will redirect the user to the Nevermined for Login
and once the user is returned to the app calling the `init` method to finalize the initialization of
the payments library.

```tsx title="/app/page.tsx"
'use client'

import { useEffect } from 'react'
import { Payments } from '@nevermined-io/payments'

export default function Home() {
const payments = new Payments({
returnUrl:
'https://docs.nevermined.app/docs/tutorials/integration/nextjs-react-payments#try-it-out',
environment: 'staging',
})

const onLogin = () => {
payments.connect()
}

useEffect(() => {
payments.init()
}, [])

return (
<main>
<div>
<button onClick={onLogin}>Login</button>
</div>
</main>
)
}
```

### Create a subscription

Once the app is initialized we can start interacting with the Nevermined Payments Protocol. Here is
a example for creating a subscription

```tsx title="/app/page.tsx"
...

async function createSubscription() {
if (payments.isLoggedIn) {
const { did } = await payments.createSubscription({
name: 'test subscription',
description: 'test',
price: 10000000n,
tokenAddress: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
duration: 30,
tags: ['test'],
})
}

return (
<main>
<div>
<button onClick={onLogin}>Login</button>
<button onClick={createSubscription}>Create Subscription</button>
</div>
</main>
)
}
```

### Try it out

<PaymentsTutorial></PaymentsTutorial>

### Full code

For the full nextjs example please check
[payments-nextjs-example](https://github.com/nevermined-io/tutorials/tree/main/payments-nextjs-example)

```tsx title="app/page.tsx"
import { useEffect, useState, useRef } from 'react'
import { Payments } from '@nevermined-io/payments'

export default function PaymentsTutorial() {
const [isUserLoggedIn, setIsUserLoggedIn] = useState<boolean>(false)
const [creatingSubscription, setCreatingSubscription] = useState<boolean>(false)
const [did, setDid] = useState<string>('')

const payments = useRef(
new Payments({
returnUrl:
'https://docs.nevermined.app/docs/tutorials/integration/nextjs-react-payments#try-it-out',
environment: 'staging',
}),
)

const onLogin = () => {
payments.current.connect()
}

useEffect(() => {
payments.current.init()
}, [])

useEffect(() => {
if (payments.current.isLoggedIn) {
setIsUserLoggedIn(true)
}
}, [payments.current.isLoggedIn])

async function createSubscription() {
if (payments.current.isLoggedIn) {
setCreatingSubscription(true)
const { did } = await payments.current.createSubscription({
name: 'test subscription',
description: 'test',
price: 10000000n,
tokenAddress: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
duration: 30,
tags: ['test'],
})
setCreatingSubscription(false)
setDid(did)
}
}

return (
<main>
<div>
<button onClick={onLogin}>Login</button>
<p>{isUserLoggedIn ? 'Logged in' : 'Not logged in'}</p>
<button onClick={createSubscription}>Create Subscription</button>
<p>
{creatingSubscription && did === '' ? (
'Creating Subscription, please wait a few seconds...'
) : (
<a href={`https://staging.nevermined.app/subscription/${did}`}>{did}</a>
)}
</p>
</div>
</main>
)
}
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@docusaurus/theme-common": "^3.1.0",
"@docusaurus/theme-search-algolia": "^3.1.0",
"@mdx-js/react": "^3.0.0",
"@nevermined-io/payments": "^0.1.2",
"@nevermined-io/styles": "^0.1.1",
"axios": "1.6.0",
"bem-helpers": "^1.1.0",
Expand Down
63 changes: 63 additions & 0 deletions src/components/payments/tutorial.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { useEffect, useState, useRef } from 'react'
import { Payments } from '@nevermined-io/payments'

export default function PaymentsTutorial() {
const [isUserLoggedIn, setIsUserLoggedIn] = useState<boolean>(false)
const [creatingSubscription, setCreatingSubscription] = useState<boolean>(false)
const [did, setDid] = useState<string>('')

const payments = useRef(
new Payments({
returnUrl:
'https://docs.nevermined.app/docs/tutorials/integration/nextjs-react-payments#try-it-out',
environment: 'staging',
}),
)

const onLogin = () => {
payments.current.connect()
}

useEffect(() => {
payments.current.init()
}, [])

useEffect(() => {
if (payments.current.isLoggedIn) {
setIsUserLoggedIn(true)
}
}, [payments.current.isLoggedIn])

async function createSubscription() {
if (payments.current.isLoggedIn) {
setCreatingSubscription(true)
const { did } = await payments.current.createSubscription({
name: 'test subscription',
description: 'test',
price: 10000000n,
tokenAddress: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
duration: 30,
tags: ['test'],
})
setCreatingSubscription(false)
setDid(did)
}
}

return (
<main>
<div>
<button onClick={onLogin}>Login</button>
<p>{isUserLoggedIn ? 'Logged in' : 'Not logged in'}</p>
<button onClick={createSubscription}>Create Subscription</button>
<p>
{creatingSubscription && did === '' ? (
'Creating Subscription, please wait a few seconds...'
) : (
<a href={`https://staging.nevermined.app/subscription/${did}`}>{did}</a>
)}
</p>
</div>
</main>
)
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This file is not used in compilation. It is here just for a nice editor experience.
"extends": "@docusaurus/tsconfig",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"target": "ES2020"
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,11 @@
dependencies:
"@types/mdx" "^2.0.0"

"@nevermined-io/payments@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@nevermined-io/payments/-/payments-0.1.2.tgz#ffff6a053dacf1755a51bd99a35644693d8c7575"
integrity sha512-40KjPcLU9KuyTyBbHDuxISAFxXPyHJX4aEtu9M/SQX+mQiIi8D+Tzn/IFgA2bxXtLjJxOWO4ZVZ0mLvrNDgFYA==

"@nevermined-io/styles@^0.1.1":
version "0.1.9"
resolved "https://registry.yarnpkg.com/@nevermined-io/styles/-/styles-0.1.9.tgz#33cd2b8e1ca2939844f2052bfeed77933ed895d6"
Expand Down

0 comments on commit caabd2b

Please sign in to comment.