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

Dev test #121

Merged
merged 90 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
66c4efa
Add permissionLevel and fix env vars names
djmbritt May 2, 2024
9e9e826
Fix name for network property in testClientSession
djmbritt May 2, 2024
0fd401f
Add transact function return type
djmbritt May 2, 2024
b63f165
Add transfer.test.ts
djmbritt May 2, 2024
cd28d05
Fix quantity type for transfer method
djmbritt May 3, 2024
16ebdec
Add transfer.test.ts
djmbritt May 3, 2024
8b37f7e
Add getPendingPayments.test.ts
djmbritt May 3, 2024
9a905ac
Merge branch 'dev' into dev_test
djmbritt May 3, 2024
e241a62
Recreate src/ structure as docs
djmbritt May 4, 2024
329a1ea
Rename env vars
djmbritt May 4, 2024
dd6f94e
Merge branch 'dev' into dev_test
djmbritt May 5, 2024
af36725
clean up camapigns docs
djmbritt May 5, 2024
669c7e8
Merge branch 'dev' into dev_test
djmbritt May 5, 2024
631a703
Add createCampaign, getCampaignById and getCamapigns docs
djmbritt May 6, 2024
4288a66
Update biome json to include docs/
djmbritt May 7, 2024
0a4411a
Update sidebar with sdk api items
djmbritt May 7, 2024
80d1a0d
Use kebab case for files in pages/
djmbritt May 7, 2024
4ee23ea
Use kebab case for sidebar items
djmbritt May 7, 2024
bb0e4ee
Update create-campaign docs
djmbritt May 7, 2024
b292640
Update getPrice doc
djmbritt May 7, 2024
480b62b
Add getBalance docs
djmbritt May 7, 2024
3378384
Add getBalance docs
djmbritt May 7, 2024
e9a8c97
Merge branch 'dev_test' of github.com:effectai/effect-js into dev_test
djmbritt May 7, 2024
a5ec36b
Add swap documentation
djmbritt May 7, 2024
5e40649
Add transact result page to glossary
djmbritt May 8, 2024
1ebbc29
Add asset docs
djmbritt May 8, 2024
edc26db
clean up get-balance and swap
djmbritt May 8, 2024
81d267e
Use NameType instead of Name
djmbritt May 10, 2024
631fcac
Fix link to transfer docs
djmbritt May 10, 2024
c639cf3
Clean up client.test.ts
djmbritt May 10, 2024
c062c98
Update test script
djmbritt May 10, 2024
a091600
clean up session.ts
djmbritt May 10, 2024
dd0a27b
Await on `createClient()` and clean up
djmbritt May 10, 2024
9ed33dc
use `await createClient()` and clean up
djmbritt May 10, 2024
b4a66a1
Update generated types
djmbritt May 10, 2024
7fdc26d
Update get-balance docs and init transfer docs
djmbritt May 10, 2024
8dcdcc1
Merge branch 'dev' into dev_test
djmbritt May 10, 2024
30106a2
Add test files
djmbritt May 10, 2024
bd60500
Add claim.test.ts
djmbritt May 10, 2024
951be62
Fix getAvatar function signature with getAvatarArgs
djmbritt May 10, 2024
7da3801
fix: export proper getAvatar function
djmbritt May 10, 2024
731bd6c
todo: getAvatar, getAsset are not working as expected
djmbritt May 10, 2024
4edc84f
implement payout.test.ts
djmbritt May 10, 2024
20955e3
Fix: use ExtendedAssetType instead of ExtendedAsset
djmbritt May 10, 2024
734badb
Add test to withdraw.test.ts
djmbritt May 10, 2024
e566b82
Add return type to `getOrCreate()` function signature
djmbritt May 10, 2024
d63b5a4
Add getOrCreate.test.ts
djmbritt May 10, 2024
ca4f195
Fix efx symbol for createBatch function
djmbritt May 10, 2024
fbf5502
Add createBatch.test.ts
djmbritt May 10, 2024
4c8f1cd
Add getBatch.test.ts
djmbritt May 10, 2024
b23eb02
Add getTaskIdx.test.ts
djmbritt May 10, 2024
2eedec9
Add getForceSettings.test.ts
djmbritt May 10, 2024
4b92a67
Add getRepititions.test.ts
djmbritt May 10, 2024
67af03a
Add getRepitionsArgs to getRepitions function
djmbritt May 10, 2024
cc7e1cd
Update getSubmissions return value
djmbritt May 10, 2024
46128da
Add getSubmission.test.ts
djmbritt May 10, 2024
1704f63
Add getTask.test.ts
djmbritt May 10, 2024
8bd5326
Clean up getReservations.ts, add return types, return object instead …
djmbritt May 10, 2024
ff9204b
add getReservations.test.ts
djmbritt May 10, 2024
d297b42
Add reserveTAsk.test.ts
djmbritt May 10, 2024
43498ab
Add submitTask.test.ts
djmbritt May 10, 2024
47d3324
Add test:only to package.json scripts
djmbritt May 10, 2024
5024bab
Clean up
djmbritt May 10, 2024
e8680d2
Update return type for getAccount
djmbritt May 11, 2024
7a3051d
Update getting-started page and use snippets
djmbritt May 11, 2024
0507117
Update campaign docs
djmbritt May 12, 2024
e0e8b52
Update get-balance docs
djmbritt May 12, 2024
d9c7236
Update get-price docs
djmbritt May 12, 2024
5534358
Update swap
djmbritt May 12, 2024
9898369
Add swapArgs to index export
djmbritt May 12, 2024
bd063fb
Update docs:dev script with `bun link`
djmbritt May 12, 2024
5c123cd
Add TODO for swap function
djmbritt May 12, 2024
87fbdf8
Update package.json dependency with link to local `@effectai/sdk`
djmbritt May 12, 2024
68400c3
Use code snippets for getting started guide
djmbritt May 12, 2024
c5f7252
Use code snippets for create campaign guide
djmbritt May 12, 2024
e7753f5
Add tasks code snippets
djmbritt May 12, 2024
e6d0a6d
Add code snippet for create account
djmbritt May 12, 2024
80d2481
Add claim to docs
djmbritt May 12, 2024
e157602
Add payout docs
djmbritt May 12, 2024
31295cd
Fix link to glossary/transaction-result
djmbritt May 12, 2024
3f6fe49
Update quantity for withdraw() to use number instead of ExtendedAsset…
djmbritt May 13, 2024
b6783fa
Add withdraw docs
djmbritt May 13, 2024
e24b1ef
Update transfer docs to use snippets
djmbritt May 13, 2024
5485254
Add deposit docs
djmbritt May 13, 2024
0e2c69b
Add create-account docs
djmbritt May 13, 2024
27756a4
Add get vaccounts doc
djmbritt May 13, 2024
76aa0fc
Add get pending paymets doc
djmbritt May 13, 2024
e4fa0fe
Add get pending paymets doc
djmbritt May 13, 2024
6d85a06
Merge branch 'dev_test' of github.com:effectai/effect-js into dev_test
djmbritt May 13, 2024
f6f20e5
chore: format
djmbritt May 13, 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
4 changes: 2 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
},
"formatter": {
"enabled": true,
"ignore": ["dist", "test", "docs"]
"ignore": ["dist", "test"]
},
"linter": {
"ignore": ["dist", "test", "scripts", "docs"],
"ignore": ["dist", "test", "scripts"],
"enabled": true,
"rules": {
"recommended": true
Expand Down
3 changes: 3 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"build": "vocs build --searchIndex false && vocs search-index",
"preview": "vocs preview"
},
"dependencies": {
"@effectai/sdk": "link:@effectai/sdk"
},
"devDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
35 changes: 3 additions & 32 deletions docs/pages/docs/collecting-data/create-a-campaign.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,9 @@ A campaign is a <u>collection of tasks</u> that need to be completed by workers.

### Creating a campaign

```ts [example.ts]
import { createCampaign } from '@effectai/effect-js'
```ts twoslash
// [!include ~/snippets/tasks/create-campaign.ts]

// get the actor from the session
const { actor } = client.session

// example template
const template = '<html>...</html>'

const campaign = await createCampaign({
client,
data: {
title: 'My first campaign',
category: 'Image Labeling', // Category of the campaign e.g. Image Labeling, Audio Transcription etc.
description: 'This is a description of my first campaign', // Description of the campaign
estimated_time: 3600, // Estimated time to complete a task in seconds
example_task: 'This is an example task',
image: 'https://example.com/image.png',
instructions: 'This is the instructions for the workers',
input_schema: null,
output_schema: null,
template,
version: 1,
},
campaign: {
owner: actor,
reward: { quantity: '1', contract: 'effecttokens' },
max_task_time: 3600,
qualis: [],
payer: actor,
},
})
```

Wooooho! You have created your first campaign. You can now view the campaign on the [Effect Network](https://app.effect.network/campaigns) before you start collecting data, you need to add tasks to the campaign. You can do this by following the [Adding Tasks](/docs/collecting-data/adding-tasks) guide.
Wooooho! You have created your first campaign. You can now view the campaign on the [Effect Network](https://app.effect.network/campaigns) before you start collecting data, you need to add tasks to the campaign. You can do this by following the [Adding Tasks](/docs/collecting-data/adding-tasks) guide.
169 changes: 48 additions & 121 deletions docs/pages/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,152 +3,79 @@
## Installation

Use your favorite package manager to install the SDK.
The sdk is available on [npm](https://www.npmjs.com/package/@effectai/sdk)

:::code-group
:::code-group

```bash [npm]
```bash [npm]
npm i @effectai/sdk
```

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

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

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

### 1. Import the SDK
### 1. Import and Instantiate the EffectAI Client

```ts
import { createClient } from '@effectai/effect-js'
```
Here the handy dandy `createClient` function is used to create a client instance.
It can three arguments, the first one is the network configuration,
the second one is the a session object, and the third one is the options object.

### 2. Instantiate the EffectAI Client
In this quick start guide we will be focusing on the first two,
how to get started with a non authenticated client using the network configuration and
an authenticated client using the session object.

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()
Here is an example of how to create a client with a network configuration.

// But currently it is like this:
import { jungle4 } from '@effectai/effect-js'
// Atleast the opts ({}) object is now optional
const client = createClient(jungle4)
```ts twoslash
// [!include ~/snippets/getting-started/getting-started-init.ts]
```

### 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",
},
}
*/

### 2. Interact with the Client

The sdk is built using a stateless model, meaning that all the functions are pure
and (almost) does not mutate the client object.
In practice this means that you wiil need to create a client object,
and pass it as an argument to the functions you want to use.

Here is an example of how to retrieve an Effect account by using its ID.

```ts twoslash
// [!include ~/snippets/getting-started/getting-started-nonauth.ts]
```

### 4. Set up wallet and session
### 3. 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 plugin is an interface that allows you to sign transactions and interact with the blockchain.

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.
Currently the SDK does not come with any wallet plugins,
and you will need to use one provided by [wharfkit.com](https://wharfkit.com/).
A list of plugins can be found at [wharfkit.com/plugins](https://wharfkit.com/plugins?sort=popular)

In this example we will use the `WalletPluginPrivateKey` plugin, which requres a private key to be passed in.
In this example we will use the [`@wharfkit/wallet-plugin-privatekey`](https://wharfkit.com/plugins/wallet-plugin-privatekey) 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.
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 });
```ts twoslash
// [!include ~/snippets/getting-started/getting-started-auth.ts]
```

## 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 });
```
## Conclusion

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.
Expand Down
21 changes: 21 additions & 0 deletions docs/pages/docs/glossary/asset.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Asset

## Description

Some functions with the `@effectai/sdk` package will return a `Asset` object.
This object contains information about tokens on the blockchain and contain information such as the symbol, precision, and amount.

An example for the `Asset` object is as follows:


```json
{
"precision": 4,
"symbol": "EFX",
"units": 10000,
"value": 1
}
```

Read more about the `Asset` object here:
https://wharfkit.com/docs/antelope/asset
26 changes: 26 additions & 0 deletions docs/pages/docs/glossary/transaction-result.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Transaction Result

## Description

Some functions with the `@effectai/sdk` package will return a `TransactionResult` object.
This object contains the transaction hash and the transaction receipt.

The interface for the `TransactionResult` object is as follows:


```ts
interface TransactResult {
chain: ChainDefinition
request: SigningRequest
resolved: ResolvedSigningRequest | undefined
response?: { [key: string]: any }
revisions: TransactRevisions
signatures: Signature[]
signer: PermissionLevel
transaction: ResolvedTransaction | undefined
}
```

Read more about the `TransactionResult` object here:

https://wharfkit.com/docs/session-kit/transact-result
65 changes: 65 additions & 0 deletions docs/pages/docs/tasks/campaigns/create-campaign.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# createCampaign

## Description

This function creates a campaign from a specified client with the given campaign parameters.
You can view the campaign on the [Effect Network](https://app.effect.network/campaigns) before you start collecting data,
you need to add tasks to the campaign. You can do this by following the [Adding Tasks](/docs/collecting-data/adding-tasks) guide.

## Usage

```ts twoslash
// [!include ~/snippets/tasks/create-campaign.ts]
```
## Output

```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,
},
}
```
## Parameters


### client
- **Type:** `SomeClient`
- **Description:** The client used to retrieve campaigns.

### CreateCampaignArgs["campaign"]
- **version**: Version number of the campaign
- **maxTaskTime**: Time maximum time in seconds for the task
- **reward**: Reward for each task in EFX
- **title**: Title of the campaign
- **description**: Description of the campaign
- **instructions**: Instructions for the campaign
- **template**: Template for the campaign, which is a string of HTML
- **input_schema**: JSON schema for each input task
- **output_schema**: JSON schema for each output task
- **image**: Image URL for the campaign
- **category**: Category of the campaign
- **example_task**: An example_task for the campaign, this should be data that will be input into the campaign
- **estimated_time**: Estimated time in seconds for the task

## Returns

**Type:** TransactionResult

**Description:**
Returns a transaction response object that contains the transaction id block number, and various properties that correlate to the transaction.
Read more about the transaction response here: [TransactionResponse](/docs/glossary/transaction-result.mdx)
Loading