docs: warp to warp-contracts

This commit is contained in:
asiaziola
2022-06-06 13:49:13 +02:00
parent 448d694dd3
commit 978466ce5e
3 changed files with 41 additions and 19 deletions

View File

@@ -97,22 +97,22 @@ SDK requires node.js version 16.5+.
#### Using npm #### Using npm
`npm install warp` `npm install warp-contracts`
#### Using yarn #### Using yarn
`yarn add warp` `yarn add warp-contracts`
### Import ### Import
You can import the full API or individual modules. You can import the full API or individual modules.
```typescript ```typescript
import * as WarpSdk from 'warp'; import * as WarpSdk from 'warp-contracts';
``` ```
```typescript ```typescript
import { Warp, Contract, ... } from 'warp' import { Warp, Contract, ... } from 'warp-contracts'
``` ```
The SDK is available in both the ESM and CJS format - to make it possible for web bundlers (like webpack) to effectively The SDK is available in both the ESM and CJS format - to make it possible for web bundlers (like webpack) to effectively

View File

@@ -3,16 +3,19 @@
This guide describes <strong>the simplest</strong> way to switch to the new version of SmartWeave. It uses `WebNodeFactory` for Node and `WarpWebFactory` for Web to quickly obtain fully configured, mem-cacheable SmartWeave instance. To see a more detailed explanation of all the core modules check out the [source code.](https://github.com/redstone-finance/warp) This guide describes <strong>the simplest</strong> way to switch to the new version of SmartWeave. It uses `WebNodeFactory` for Node and `WarpWebFactory` for Web to quickly obtain fully configured, mem-cacheable SmartWeave instance. To see a more detailed explanation of all the core modules check out the [source code.](https://github.com/redstone-finance/warp)
### You can watch this tutorial on YouTube 🎬 ### You can watch this tutorial on YouTube 🎬
- [Youtube link](https://www.youtube.com/watch?v=fNjUV7mHFqw) - [Youtube link](https://www.youtube.com/watch?v=fNjUV7mHFqw)
[![warp migration guide](https://img.youtube.com/vi/fNjUV7mHFqw/0.jpg)](https://www.youtube.com/watch?v=fNjUV7mHFqw) [![warp migration guide](https://img.youtube.com/vi/fNjUV7mHFqw/0.jpg)](https://www.youtube.com/watch?v=fNjUV7mHFqw)
### Need help? 🙋‍♂️ ### Need help? 🙋‍♂️
Please feel free to contact us [on Discord](https://redstone.finance/discord) if you face any problems. Please feel free to contact us [on Discord](https://redstone.finance/discord) if you face any problems.
## 1. Update dependencies 📦 ## 1. Update dependencies 📦
#### 1.1 Install Warp #### 1.1 Install Warp
```bash ```bash
# Yarn # Yarn
yarn add warp yarn add warp
@@ -20,8 +23,11 @@ yarn add warp
# or NPM # or NPM
npm install warp npm install warp
``` ```
#### 1.2 Remove smartweave v1 #### 1.2 Remove smartweave v1
If smartweave was installed globally, add `-g` flag to npm or use `yarn global` If smartweave was installed globally, add `-g` flag to npm or use `yarn global`
```bash ```bash
# Yarn # Yarn
yarn remove smartweave yarn remove smartweave
@@ -31,25 +37,29 @@ npm uninstall smartweave
``` ```
#### 1.3 Replace imports #### 1.3 Replace imports
You can import the full API or individual modules. You can import the full API or individual modules.
```typescript ```typescript
import * as WarpSdk from 'warp'; import * as WarpSdk from 'warp-contracts';
import { Warp, Contract, ... } from 'warp'; import { Warp, Contract, ... } from 'warp-contracts';
``` ```
## 2. Update your implementation 🧑‍💻 ## 2. Update your implementation 🧑‍💻
### 2.1 Initialize a Warp client ### 2.1 Initialize a Warp client
```typescript ```typescript
import Arweave from 'arweave'; import Arweave from 'arweave';
import { WarpNodeFactory } from 'warp'; import { WarpNodeFactory } from 'warp-contracts';
// Create an Arweave instance // Create an Arweave instance
const arweave = Arweave.init({ const arweave = Arweave.init({
host: "dh48zl0solow5.cloudfront.net", host: 'dh48zl0solow5.cloudfront.net',
port: 443, port: 443,
protocol: "https", protocol: 'https',
timeout: 20000, timeout: 20000,
logging: false, logging: false
}); });
// Create a Warp client // Create a Warp client
@@ -59,31 +69,37 @@ const smartweave = WarpNodeFactory.memCached(arweave);
For Web environment you should use `WarpWebFactory` instead of `WarpNodeFactory`. For Web environment you should use `WarpWebFactory` instead of `WarpNodeFactory`.
In this example we've used the `memCached` method. You can see other available methods in documentation: In this example we've used the `memCached` method. You can see other available methods in documentation:
- [For Web](https://smartweave.docs.redstone.finance/classes/SmartWeaveWebFactory.html) - [For Web](https://smartweave.docs.redstone.finance/classes/SmartWeaveWebFactory.html)
- [For Node.js](https://smartweave.docs.redstone.finance/classes/SmartWeaveNodeFactory.html) - [For Node.js](https://smartweave.docs.redstone.finance/classes/SmartWeaveNodeFactory.html)
#### [Optional] Custom modules 🛠 #### [Optional] Custom modules 🛠
Warp has a modular architecture, which allows you to connect custom modules to any part of the Warp client implementation. See [custom-client-example.ts](https://github.com/redstone-finance/redstone-smartweave-examples/blob/main/src/custom-client-example.ts) to learn more. Warp has a modular architecture, which allows you to connect custom modules to any part of the Warp client implementation. See [custom-client-example.ts](https://github.com/redstone-finance/redstone-smartweave-examples/blob/main/src/custom-client-example.ts) to learn more.
### 2.2 Initialize contract object ### 2.2 Initialize contract object
```typescript ```typescript
// Simple connection (allows to read state) // Simple connection (allows to read state)
const contract = warp.contract("YOUR_CONTRACT_TX_ID"); const contract = warp.contract('YOUR_CONTRACT_TX_ID');
``` ```
💡 Note! For being able to write interactions to blockchain you need to connect wallet to contract object. 💡 Note! For being able to write interactions to blockchain you need to connect wallet to contract object.
```typescript ```typescript
const contract = warp const contract = warp
.contract("YOUR_CONTRACT_TX_ID") .contract('YOUR_CONTRACT_TX_ID')
.connect(jwk) // jwk should be a valid private key (in JSON Web Key format) .connect(jwk) // jwk should be a valid private key (in JSON Web Key format)
.setEvaluationOptions({ .setEvaluationOptions({
// with this flag set to true, the write will wait for the transaction to be confirmed // with this flag set to true, the write will wait for the transaction to be confirmed
waitForConfirmation: true, waitForConfirmation: true
}); });
``` ```
### 2.3 Interact with your contract ### 2.3 Interact with your contract
#### Read state (readContract in V1) #### Read state (readContract in V1)
```typescript ```typescript
// Read state (similar to the "readContract" from SmartWeave V1) // Read state (similar to the "readContract" from SmartWeave V1)
const { state, validity } = await contract.readState(); const { state, validity } = await contract.readState();
@@ -95,6 +111,7 @@ const { state, validity } = await contract.readState();
``` ```
#### View state (interactRead in V1) #### View state (interactRead in V1)
```typescript ```typescript
// View state (similar to the "interactRead" from SmartWeave V1) // View state (similar to the "interactRead" from SmartWeave V1)
const { result } = await contract.viewState<Input, View>({ const { result } = await contract.viewState<Input, View>({
@@ -104,6 +121,7 @@ const { result } = await contract.viewState<Input, View>({
``` ```
#### Write interaction (interactWrite in V1) #### Write interaction (interactWrite in V1)
```typescript ```typescript
// Write interaction (similar to the "interactWrite" from SmartWeave V1) // Write interaction (similar to the "interactWrite" from SmartWeave V1)
const result = await contract.writeInteraction({ const result = await contract.writeInteraction({
@@ -115,28 +133,32 @@ const result = await contract.writeInteraction({
💡 You can read detailed explanation of each contract method [here.](CONTRACT_METHODS.md) 💡 You can read detailed explanation of each contract method [here.](CONTRACT_METHODS.md)
### [Optional] 2.4 Confgure logging ### [Optional] 2.4 Confgure logging
Warp uses `tslog` library for logging. By default logger is set to "debug" level, which means that all messages with level "debug" or higher are logged. Warp uses `tslog` library for logging. By default logger is set to "debug" level, which means that all messages with level "debug" or higher are logged.
#### Update logger options #### Update logger options
```typescript ```typescript
LoggerFactory.INST.setOptions({ LoggerFactory.INST.setOptions({
type: "json", type: 'json',
displayFilePath: "hidden", displayFilePath: 'hidden',
displayInstanceName: false, displayInstanceName: false,
minLevel: "info", minLevel: 'info'
}); });
``` ```
Learn more about available logging options in [tslog documentation.](https://tslog.js.org/tsdoc/interfaces/isettingsparam.html) Learn more about available logging options in [tslog documentation.](https://tslog.js.org/tsdoc/interfaces/isettingsparam.html)
#### Update logger level #### Update logger level
Instead of updaitng all logger options you can simply set the new minimum logger level Instead of updaitng all logger options you can simply set the new minimum logger level
```typescript ```typescript
LoggerFactory.INST.logLevel("info"); LoggerFactory.INST.logLevel('info');
``` ```
Available log levels are listed [here.](https://github.com/redstone-finance/warp/blob/main/src/logging/RedStoneLogger.ts#L1) Available log levels are listed [here.](https://github.com/redstone-finance/warp/blob/main/src/logging/RedStoneLogger.ts#L1)
## 3. Test everything 🔥 ## 3. Test everything 🔥
Before deploying your changes test it carefully. If you face any problems please contact us [on our discord](https://redstone.finance/discord). We'll be happy to help 😊 Before deploying your changes test it carefully. If you face any problems please contact us [on our discord](https://redstone.finance/discord). We'll be happy to help 😊

View File

@@ -1,5 +1,5 @@
{ {
"name": "warp", "name": "warp-contracts",
"version": "1.0.0", "version": "1.0.0",
"description": "An implementation of the SmartWeave smart contract protocol.", "description": "An implementation of the SmartWeave smart contract protocol.",
"main": "./lib/cjs/index.js", "main": "./lib/cjs/index.js",