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

Devdocs #114

Merged
merged 71 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
0323104
Fix getPrice method
djmbritt Apr 23, 2024
86183ac
Add ClientOpts info
djmbritt Apr 23, 2024
8f1ef83
Rename files to use CamelCases
djmbritt Apr 23, 2024
4a844d0
Add compatibility info
djmbritt Apr 23, 2024
dbb5657
Remove migration link
djmbritt Apr 23, 2024
0202103
Fix getDefiBoxPair fetch method
djmbritt Apr 23, 2024
8109805
Use window.fetch or fetch for getDefiBocPair
djmbritt Apr 24, 2024
03ac5fc
Use include biome for test folder
djmbritt Apr 24, 2024
486efdd
Set up create test client helper
djmbritt Apr 24, 2024
2a212a2
test client setup
djmbritt Apr 24, 2024
32323c4
Update getting started docs with first draft
djmbritt Apr 24, 2024
322eaf6
Add getVAccounts test
djmbritt Apr 24, 2024
421104e
Merge branch 'devdocs' of github.com:effectai/effect-js into devdocs
djmbritt Apr 24, 2024
a6abb19
Fix link
djmbritt Apr 24, 2024
39b9439
Use bun test instead of vitest
djmbritt Apr 24, 2024
a83e4c3
Create vaccount test
djmbritt Apr 24, 2024
8083303
Update package.json, add coverage script, rm vitest
djmbritt Apr 24, 2024
5a14b8a
Move test files into src/ folder
djmbritt Apr 24, 2024
5dd95b1
Add .env files, use bun env var config
djmbritt Apr 24, 2024
ea489d7
Move helper to testhelper.ts
djmbritt Apr 24, 2024
4bd6030
Use bun env config, and refactor network env check
djmbritt Apr 24, 2024
acfcf46
Add info to readme about .env
djmbritt Apr 24, 2024
db9d494
Refactor to use testhelper.ts
djmbritt Apr 24, 2024
8ac08bb
Destructure env vars, and rename env vars
djmbritt Apr 24, 2024
e45c9f7
Exclude test files from build tsconfig
djmbritt Apr 24, 2024
0e1cd15
Rm console.debug
djmbritt Apr 24, 2024
b9b8cb4
Add EfxMainnetConfig contracts
djmbritt Apr 25, 2024
0e5b1dc
Add test file for getAccountAssets
djmbritt Apr 26, 2024
697175e
Use testnet / mainnet test for getVaccounts
djmbritt Apr 26, 2024
0186f8b
Add test getAccountById should throw error
djmbritt Apr 26, 2024
66bc738
Use process.env
djmbritt Apr 26, 2024
8261e20
Log wich network is used for test
djmbritt Apr 26, 2024
5bc23e7
Add documentation for client.ts
djmbritt Apr 26, 2024
a14f597
Fix gettingStarted guide
djmbritt Apr 26, 2024
7cafe65
Add documentation for createAccount.ts
djmbritt Apr 27, 2024
0e404f3
Clean up and use config for token symbol
djmbritt Apr 27, 2024
beb8813
Add createAccount.test.ts
djmbritt Apr 27, 2024
814e061
Use full example for getting started guide
djmbritt Apr 27, 2024
8af368c
Rename destructure parameters for creating Session
djmbritt Apr 28, 2024
e75d467
Add introduction
djmbritt Apr 28, 2024
b0dc14d
Add types buildSwapActionArgs and swapArgs
djmbritt Apr 29, 2024
6fbfddd
Add token.test.ts
djmbritt Apr 29, 2024
1d922e9
Change testHelper to use both testnet and mainnet env config
djmbritt Apr 29, 2024
95f9e65
Update client.test.ts to test both testnet and mainnet config
djmbritt Apr 29, 2024
758a1aa
Test getAccountAssets
djmbritt Apr 29, 2024
c2e11b2
Test getAccountAssets
djmbritt Apr 29, 2024
7889744
Use an enum for swap parameters
djmbritt Apr 29, 2024
0deb77e
Flesh out introduction
djmbritt Apr 29, 2024
c2a035d
Add test for token swapping
djmbritt Apr 29, 2024
b1e8894
Change parameter for testClientSession
djmbritt Apr 29, 2024
067b034
Formatting for getprice.ts
djmbritt Apr 29, 2024
91d5334
Fix merge error
djmbritt Apr 29, 2024
ddca5be
Add docs for getBalance
djmbritt Apr 30, 2024
15bda78
Add deposit test
djmbritt Apr 30, 2024
7fddc02
Tighten types for Session
djmbritt Apr 30, 2024
3aa8ba2
Use jungle for deposit test
djmbritt Apr 30, 2024
6c36163
Add comment on how to powerup
djmbritt Apr 30, 2024
65a733a
Use swap update from Jeff
djmbritt Apr 30, 2024
9f355a4
Update Test
djmbritt Apr 30, 2024
32f1aa5
Merge branch 'dev' into devdocs
djmbritt Apr 30, 2024
292a47d
Clean up imports for client
djmbritt Apr 30, 2024
f51e241
Add SwapArgs type
djmbritt Apr 30, 2024
973505e
Update token.test.ts with SwapArgs and add should fail when amount is…
djmbritt Apr 30, 2024
e72f3c5
Update lockfile
djmbritt Apr 30, 2024
f512676
chore: format
djmbritt Apr 30, 2024
88662b1
Add getCampaignById test
djmbritt May 1, 2024
1bd37b3
Merge branch 'devdocs' of github.com:effectai/effect-js into devdocs
djmbritt May 1, 2024
7e95aed
Add getAllCampaigns, createCampaign, getCampaigns test
djmbritt May 1, 2024
c681c7a
Add getAllCampaigns, createCampaign, getCampaigns test
djmbritt May 1, 2024
ed8bc76
Add createCampaign docs
djmbritt May 1, 2024
980f045
Merge branch 'devdocs' of github.com:effectai/effect-js into devdocs
djmbritt May 1, 2024
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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PERMISSION=active
NETWORK_NAME=mainnet
ACTOR=eosaccountname
PRIVATE_KEY=private_key_here
PUBLIC_KEY=public_key_here
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ lerna-debug.log*
.env.development.local
.env.test.local
.env.production.local
.env.testnet
.env.mainnet
.envrc

# ignore lock files other then bun.
package-lock.json
yarn.lock
yarn.lock
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ If you want to add contributions to this repository, please follow the instructi
## 🏠 Local Development
Follow the docs to Set Up Your Local Development Environment to contribute to the framework and documentation.

### Testing

#### `.env`

To run the tests locally, you will need to provide an EOS account that can be used to make transactions on your behalf.
Copy the `.env.example` file to `.env.testnet` and fill in the required parameters.

#### PowerUp

You might need to power up your account, either by adding some Native Token to your account or EFX tokens.
You can powerup your account at the following link: https://monitor4.jungletestnet.io/


Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion docs/pages/docs/compatibility.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Compatibility

The Effect AI SDK is compatible with all Node.js environments, including browsers and React Native.
The Effect AI SDK is compatible with all Node.js environments, including browsers and React Native.
It might be necessary to use a particular `fetch` polyfill in some environments.
You can read more about it [here](./glossary/client_options.mdx)
14 changes: 0 additions & 14 deletions docs/pages/docs/getting-started.mdx

This file was deleted.

157 changes: 157 additions & 0 deletions docs/pages/docs/gettingStarted.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Getting Started [Get started with the SDK in just a few lines of code.]

## Overview

## Installation

Use your favorite package manager to install the SDK.

:::code-group

```bash [npm]

npm i @effectai/effect-js
```

```bash [bun]
bun i @effectai/effect-js
```

```bash [pnpm]
pnpm i @effectai/effect-js
```
:::
## Quick Start

### 1. Import the SDK

```ts
import { createClient } from '@effectai/effect-js'
```

### 2. Instantiate the EffectAI Client

Here the handy dandy `createClient` function is used to create a client instance.
It takes two optional arguments, the first one is the network configuration, the second one is the options object.
You can read more about the options object in the [ClientOptions](#client-options) section.

```ts
// This would be ideal, the big question is if using mainnet should be explicitly passed or not.
const client = createClient()

// But currently it is like this:
import { jungle4 } from '@effectai/effect-js'
// Atleast the opts ({}) object is now optional
const client = createClient(jungle4)
```

### 3. Interact with the Client

The sdk is built using a stateless model, meaning that all the functions are pure and do not mutate the client object.
This means, that you need to creat one client, and you can pass that client as an argument to functions to make transactions.

Here is an example of how to get the balance of an account, assuming that the client is already set up as described above.

```ts
import { getVAccounts, getAccountById } from "@effectai/effect-js";
import { Name } from "@wharfkit/antelope";

const actor = Name.from("forcedev1234");
// Notice we are passing the clinet as an argument to the function.
const [vacc] = await getVAccounts({ client, actor });

console.log(vacc)
/**
{
id: 24,
nonce: 0,
address: [ "name", "forcedev1234" ],
balance: {
quantity: "0.0000 EFX",
contract: "efxtoken1112",
},
}
*/
```

### 4. Set up wallet and session

If you want to make transactions, such as creating a new account, creating a new tasks, or transfering tokens, you need to set up a wallet and a session.
The wallet plguin is an interface that allows you to sign transactions and interact with the blockchain.
The SDK comes with a few wallet plugins out of the box, but you can also create your own.

In this example we will use the `WalletPluginPrivateKey` plugin, which requres a private key to be passed in.

Afterwards we can set up the Session object, which allows us to specify other parameters like the actor, permission, and the blockchain netork.

Last but not least we connect the session to the client, and the client will be ready to use.

```ts
import { createBatch, createVAccount } from "@effectai/effect-js";
import { Session } from "@wharfkit/session";
import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"

const walletPlugin = new WalletPluginPrivateKey("your_private_key_here")

const session = new Session({
actor: "forcedev1234",
permission: "active",
walletPlugin,
chain: {
id: jungle4.eosChainId,
url: jungle4.eosRpcUrl,
},
})

// Connect the session to the client.
await session.setSession(session)

// Now you can use the client to make authenticated transactions.
const account = Name.from("efxforce1112");
await createVAccount({ client, account });
```

## Full example

```ts
import { Session, Name } from "@wharfkit/session";
import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey";
import {
createClient,
jungle4,
eos, // Use `eos` to use mainnet
getVAccounts,
createVAccount,
} from "@effectai/effect-js";

const client = createClient({ network: jungle4 });

// Make unauthenticated requests
const actor = Name.from("forcedev1234");
const [vacc] = await getVAccounts({ client, actor });

// Set up wallet with privatekey
const walletPlugin = new WalletPluginPrivateKey("your_private_key_here");

// Set up session with wallet and chain
const session = new Session({
actor: "forcedev1234",
permission: "active",
walletPlugin,
chain: {
id: jungle4.eosChainId,
url: jungle4.eosRpcUrl,
},
});

// Connect session to client
await client.setSession(session);

// Now you can use the client to make authenticated transactions.
const account = Name.from("efxforce1112");
await createVAccount({ client, account });
```

Now that we have a basic understaning of how to set up the client, we can move on to more advanced topics.
Read more on the following pages.

50 changes: 50 additions & 0 deletions docs/pages/docs/glossary/clientOptions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Client Options

The ClientOpts interface is used to define the options that can be passed to the EffectAI Client constructor.

```typescript
interface ClientOpts {
ipfsCacheDurationInMs?: number | null;
fetchProvider?: FetchProviderOptions;
cacheImplementation?: Cache;
}
```

As we can see, the ClientOpts interface has three optional properties:

## `ipfsCacheDurationIMs`

This property is used to set the cache duration for the IPFS data.
The default value is 600_000 milliseconds; 10 minutes.

## `fetchProfider`

This property is used to set the fetch provider.
This is needed because of the different runtimes availalbe to Java Script.
For example, in older versions of Node.js, the fetch API is not available.
For older versions of Node.js, you can use the [`node-fetch` ](https://github.com/node-fetch/node-fetch) package.

Since Node.js v18.0.0, the fetch API is available by default.

In the browser fetch is generally available, and is available on the `window.fetch` object.
You can read more about it here: [MDN Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)

Other serverside Java Script runtimes such as [Bun](https://bun.sh/) and (Deno)[https://deno.com/] already have fetch available on the global `fetch` object.

## `cacheImplementation`

This property is used to set the cache implementation.
There are three different cache mechanigms abailable in the EffectAI SDK.
First of all, "IDBCache", "LocalStorageCache", "MemoryCache".
Any of these can be passed to the `cacheImplementation` property while instanlizing the EffectAI Client.

```typescript
import { createClient, IDBCache, LocalStorageCache, MemoryCache } from '@effectai/sdk'
const client = createClient({
cacheImplementation: new IDBCache() // or new LocalStorageCache() or new MemoryCache()
})
```

# TODO: This needs to be changed when the `dev` branch is merged into main.
[See Type](https://github.com/effectai/effect-js/blob/main/src/client.ts)

3 changes: 0 additions & 3 deletions docs/pages/docs/guides/create-a-campaign.mdx

This file was deleted.

90 changes: 90 additions & 0 deletions docs/pages/docs/guides/createACampaign.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
## Creating Your First Campaign

To create a campaign, you need to have a few things in place:


# Create and upload campaign

## Usage

```ts [example.ts]
import { createClient, createCampaign } from '@effectai/effect-js'

const campaign: Mkcampaign = {
owner: ["name", "efxefxefxefx"],
content: {
field_0: 0,
field_1: "QmVKwq3bYM6cPW6kstpiq4WYckWRtdfJnzAmms2iMyGqQg",
},
max_task_time: 100,
reward: { quantity: "42.1234, EFX", contract: "efxtoken1112" },
qualis: [],
payer: "efxefxefxefx",
};

const data = {
version: 1.1,
title: "Labelstudio OCR (LAION)",
description:
"You are contributing to a dataset for conversational style chatbots.",
instructions: "Some instructions here",
template: "<h1>Template here</h1>",
input_schema: null,
output_schema: null,
image: "",
category: "",
example_task: "",
estimated_time: 10,
};

const client = await testClientSession({ testEnvNetwork: jungle4 });
const result = await createCampaign({ client, campaign, data });
```

## Returns

Result is a transaction response object.

```json
response: {
transaction_id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2",
processed: {
id: "9d321af28b7354c5cbee6ee956ea3e6590228b48539a9f0cafc6a8ca5ffe0ca2",
block_num: 137520447,
block_time: "2024-05-01T03:55:31.500",
producer_block_id: null,
receipt: [Object ...],
elapsed: 4854,
net_usage: 176,
scheduled: false,
action_traces: [
[Object ...]
],
account_ram_delta: null,
except: null,
error_code: null,
},
}
```


- **Type:** [`Promise<GetTableRowsResponse<UInt128, Campaign>>`](/docs/glossary/types#campaign)
- **Description:** A list of campaigns.
- **Properties:**
- **rows:** An array of campaigns.
- **more:** A boolean indicating if there are more campaigns to fetch.
- **next_key:** A string that can be used to fetch the next page of campaigns.

## Parameters

### client
- **Type:** `Client`

### limit (optional)
- **Type:** `number`
- **Default:** `10`

### page (optional)
- **Type:** `number`
- **Default:** `1`

Loading
Loading