Skip to content

Commit

Permalink
add server side usage docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Envoy-VC committed Dec 20, 2023
1 parent de02a71 commit b383a76
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 7 deletions.
18 changes: 15 additions & 3 deletions apps/docs/guides/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
---
icon: 'sitemap'
description:
'Practical step-by-step guides to help you achieve a specific goal. These
guides are designed to help you get started with a specific task or feature.'
description: 'Learn how to use Atomic Toolkit in your node and browser environments.'
---

### Usage

<CardGroup cols={2}>
<Card href="/usage/installation" title="Installation" icon="circle-down">
Install Atomic Toolkit
</Card>
<Card href="/usage/server-side" title="Server-side Usage" icon="server">
Use Atomic Toolkit in your node environments.
</Card>
<Card href="/usage/browser" title="Client-side Usage" icon="chrome">
Use Atomic Toolkit in your browser environments.
</Card>
</CardGroup>
7 changes: 5 additions & 2 deletions apps/docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"light": "/logo/light.svg"
},
"favicon": "/favicon.svg",
"feedback": {
"thumbsRating": true,
"suggestEdit": true
},
"colors": {
"primary": "#4779FF",
"light": "#6AA5FF",
Expand Down Expand Up @@ -93,7 +97,6 @@
"backgroundImage": "https://ty4fqyqcpuijbv4cgpj46eesp7usbxaf5sqd3fcvkhayp5r4l4sq.arweave.dev/njhYYgJ9EJDXgjPTzxCSf-kg3AXsoD2UVVHBh_Y8XyU",
"footerSocials": {
"twitter": "https://twitter.com/Envoy_1084",
"github": "https://github.com/Envoy-VC/atomic-toolkit",
"linkedin": "https://www.linkedin.com/in/vedant-chainani"
"github": "https://github.com/Envoy-VC/atomic-toolkit"
}
}
24 changes: 24 additions & 0 deletions apps/docs/usage/installation.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
---
title: Installation
---

## Requirements

- Node.js (version 16 or higher)
- npm (version 5.6 or higher) or yarn or pnpm

## Installation

<CodeGroup>
```bash npm
npm install atomic-toolkit
```

```bash yarn
yarn add atomic-toolkit
```

```bash pnpm
pnpm add atomic-toolkit
```

</CodeGroup>


93 changes: 93 additions & 0 deletions apps/docs/usage/server-side.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,96 @@
---
title: Server-side Usage
description: Use Atomic Toolkit in Server Environments
---

This section guides you through initializing Atomic Toolkit within a server environment like a backend application. Currently Atomic toolkit can be initializing in the following ways:

1. Using Arweave Wallet
2. Using Irys SDK

## Using Arweave Wallet

It uses the Arweave Wallet to sign transactions and interact with the Arweave network.

```ts
import { readFileSync } from 'fs';
import AtomicToolkit from 'atomic-toolkit';

const key = JSON.parse(readFileSync('wallet.json').toString());

const atomicToolkit = new AtomicToolkit({
environment: 'mainnet',
jwk: key,
});
```

### Input Parameters

The following params are available for this function and they must be passed in as an object:

- **environment**: `mainnet` | `testnet`: The environment to use. If testnet is used, warp for testnet will be used.
- **warp (optional)**: `Warp`: A Warp Instance to use with Deploy Plugin. If not provided, the default Warp instance for Mainnet will be used.
- **arweave (optional)**: `Arweave`: An Arweave Instance to use. If not provided, the default Arweave instance with gateway [arweave.net](arweave.net) will be used.
- **jwk**: `JWKInterface`: The Key to use for signing transactions. Should be a JWK object.

<Warning>
Private keys must be kept secure at all times. Please ensure that the
`wallet.json` file is not pushed to a version control (eg. GitHub). If you
are using a CI/CD pipeline, ensure that the wallet.json file is not stored
in the repository.
</Warning>

<Note>
The Warp instance should use the `DeployPlugin`. It is neccessary to
register Atomic Assets
</Note>

### Default Values

```ts
/**
* Default Warp instance
*/
const warp = WarpFactory.forMainnet().use(new DeployPlugin());

/**
* Default Arweave configuration.
*/
const defaultArweave = new Arweave({
host: 'arweave.net',
port: 443,
protocol: 'https',
});
```

### Custom Instance Example

```ts
import Arweave from 'arweave';
import { readFileSync } from 'fs';
import AtomicToolkit from 'atomic-toolkit';
import { DeployPlugin } from 'warp-contracts-plugin-deploy';
import { WarpFactory, defaultCacheOptions } from 'warp-contracts';

const key = JSON.parse(readFileSync('wallet.json').toString());

const warp = WarpFactory.forMainnet().use(new DeployPlugin());

const arweave = new Arweave({
host: 'arweave.net',
port: 443,
protocol: 'https',
});

const warp = WarpFactory.forMainnet({
...defaultCacheOptions,
inMemory: true,
}).use(new DeployPlugin());

const atomicToolkit = new AtomicToolkit({
environment: 'mainnet',
warp,
arweave,
jwk: key,
});
```
3 changes: 3 additions & 0 deletions packages/atomic-toolkit/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export type AtomicToolkitWithArweave = {
* Arweave Configuration Options(either arweave or irys)
*/
useIrys?: false;
/**
* Arweave Configuration Options
*/
arweave?: Arweave;
jwk: JWKInterface;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/atomic-toolkit/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Arweave from 'arweave';
import Irys, { WebIrys } from '@irys/sdk';

import AtomicToolkit, { AtomicToolkitWeb } from '../src';
import { Warp } from 'warp-contracts';
import { Warp, WarpFactory } from 'warp-contracts';

describe('AtomicToolkit Class', () => {
it('should create an instance with Arweave', async () => {
Expand Down Expand Up @@ -90,4 +90,4 @@ describe('AtomicToolkitWeb Class', () => {
expect(toolkit.arweave).to.equal(null);
expect(toolkit.irys).to.equal(irys);
});
});
});

0 comments on commit b383a76

Please sign in to comment.