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

Support Node.js #65

Merged
merged 17 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
26 changes: 25 additions & 1 deletion manta-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ This package implements a Javascript SDK for connecting with the Manta Network.
yarn install manta.js
```

> If using sdk in a node.js environment please go to [Node Specific](#node-specific)

### Local Development

1. `git clone https://github.com/Manta-Network/sdk.git`
2. `cd sdk/manta-js/package`
3. `yarn`
4. `yarn build`
4. `yarn build-all` (Note: go to [Node Specific](#node-specific) if running in node.js environment)
5. add `"manta.js": "file:/{LOCAL PATH OF sdk/manta-js/package}` to your project's package.json
6. `yarn upgrade manta.js` in your project's directory

Expand All @@ -27,6 +29,28 @@ All methods are called through the `MantaPrivateWallet` class.

Refer to `/examples` for more thorough examples, and how to run them.

## Node Specific

If running in node.js the wasm module assumes browser DOM exists, you must export Web API functions from node in your project as seen below.

Node supported package is exported using the following path: `manta.js/node` see code snippit below.

This node package is only compatible with node16 and up, if using typescript you must set ```"moduleResolution": "node16"``` in `tsconfig.json` or as a compiler flag

```javascript
import { MantaPrivateWallet, Environment, Network } from 'manta.js/node'
import fetch from 'node-fetch';

// @ts-ignore
global.fetch = fetch;
// @ts-ignore
global.Headers = fetch.Headers;
// @ts-ignore
global.Request = fetch.Request;
// @ts-ignore
global.Response = fetch.Response;
```

## Initialization

The `Environment` flag specifies whether to connect to a local node, or the use an actual node from the network.
Expand Down
Loading