docs: additional docs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# SmartWeave SDK v2 - Contract methods
|
||||
# Warp - Contract methods
|
||||
|
||||
- [Contract Methods](#contract-methods)
|
||||
- [`connect`](#connect)
|
||||
@@ -6,27 +6,27 @@
|
||||
- [`readState`](#readstate)
|
||||
- [`viewState`](#viewstate)
|
||||
- [`writeInteraction`](#writeinteraction)
|
||||
- [`bundleInteraction`](#bundleInteraction)
|
||||
|
||||
## Contract Methods
|
||||
|
||||
### `connect`
|
||||
|
||||
```typescript
|
||||
async function connect(wallet: ArWallet): Contract<State>
|
||||
async function connect(wallet: ArWallet): Contract<State>;
|
||||
```
|
||||
|
||||
Allows to connect wallet to a contract. Connecting a wallet MAY be done before "viewState" (depending on contract implementation, ie. whether called contract's function required "caller" info) Connecting a wallet MUST be done before "writeInteraction".
|
||||
|
||||
- `wallet` a JWK object with private key or 'use_wallet' string.
|
||||
- `wallet` a JWK object with private key or 'use_wallet' string.
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```typescript
|
||||
const contract = smartweave
|
||||
.contract("YOUR_CONTRACT_TX_ID")
|
||||
.connect(jwk);
|
||||
```
|
||||
```typescript
|
||||
const contract = smartweave.contract('YOUR_CONTRACT_TX_ID').connect(jwk);
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
@@ -34,49 +34,50 @@ Allows to connect wallet to a contract. Connecting a wallet MAY be done before "
|
||||
### `setEvaluationOptions`
|
||||
|
||||
```typescript
|
||||
function setEvaluationOptions(options: Partial<EvaluationOptions>): Contract<State>
|
||||
function setEvaluationOptions(options: Partial<EvaluationOptions>): Contract<State>;
|
||||
```
|
||||
|
||||
Allows to set (EvaluationOptions)
|
||||
|
||||
|
||||
- `options` the interaction input
|
||||
- `options.ignoreExceptions` enables exceptions ignoring
|
||||
- `options.waitForConfirmation` enables waiting for transaction confirmation
|
||||
- `options` the interaction input
|
||||
- `options.ignoreExceptions` enables exceptions ignoring
|
||||
- `options.waitForConfirmation` enables waiting for transaction confirmation
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```typescript
|
||||
const contract = smartweave
|
||||
.contract("YOUR_CONTRACT_TX_ID")
|
||||
.setEvaluationOptions({
|
||||
waitForConfirmation: true,
|
||||
ignoreExceptions: false,
|
||||
});
|
||||
```
|
||||
```typescript
|
||||
const contract = smartweave.contract('YOUR_CONTRACT_TX_ID').setEvaluationOptions({
|
||||
waitForConfirmation: true,
|
||||
ignoreExceptions: false
|
||||
});
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
|
||||
|
||||
### `readState`
|
||||
|
||||
```typescript
|
||||
async function readState(blockHeight?: number, currentTx?: { contractTxId: string; interactionTxId: string }[]): Promise<EvalStateResult<State>>
|
||||
async function readState(
|
||||
blockHeight?: number,
|
||||
currentTx?: { contractTxId: string; interactionTxId: string }[]
|
||||
): Promise<EvalStateResult<State>>;
|
||||
```
|
||||
|
||||
Returns state of the contract at required blockHeight. Similar to the `readContract` from the version 1.
|
||||
|
||||
- `blockHeight` Block height for state
|
||||
- `currentTx` If specified, will be used as a current transaction
|
||||
- `blockHeight` Block height for state
|
||||
- `currentTx` If specified, will be used as a current transaction
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```typescript
|
||||
const { state, validity } = await contract.readState();
|
||||
```
|
||||
```typescript
|
||||
const { state, validity } = await contract.readState();
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
@@ -84,25 +85,31 @@ Returns state of the contract at required blockHeight. Similar to the `readContr
|
||||
### `viewState`
|
||||
|
||||
```typescript
|
||||
async function viewState<Input, View>(input: Input, blockHeight?: number, tags?: Tags, transfer?: ArTransfer): Promise<InteractionResult<State, View>>
|
||||
async function viewState<Input, View>(
|
||||
input: Input,
|
||||
blockHeight?: number,
|
||||
tags?: Tags,
|
||||
transfer?: ArTransfer
|
||||
): Promise<InteractionResult<State, View>>;
|
||||
```
|
||||
|
||||
Returns the "view" of the state, computed by the SWC - ie. object that is a derivative of a current state and some specific smart contract business logic. Similar to the `interactRead` from the current SDK version.
|
||||
|
||||
- `input` the interaction input
|
||||
- `blockHeight` if specified the contract will be replayed only to this block height
|
||||
- `tags` an array of tags with name/value as objects
|
||||
- `transfer` target and winstonQty for transfer
|
||||
- `input` the interaction input
|
||||
- `blockHeight` if specified the contract will be replayed only to this block height
|
||||
- `tags` an array of tags with name/value as objects
|
||||
- `transfer` target and winstonQty for transfer
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```typescript
|
||||
const { result } = await contract.viewState<any, any>({
|
||||
function: "NAME_OF_YOUR_FUNCTION",
|
||||
data: { ... }
|
||||
});
|
||||
```
|
||||
```typescript
|
||||
const { result } = await contract.viewState<any, any>({
|
||||
function: "NAME_OF_YOUR_FUNCTION",
|
||||
data: { ... }
|
||||
});
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
@@ -110,25 +117,29 @@ Returns the "view" of the state, computed by the SWC - ie. object that is a deri
|
||||
### `viewStateForTx`
|
||||
|
||||
```typescript
|
||||
async function viewStateForTx<Input, View>(input: Input, transaction: InteractionTx): Promise<InteractionResult<State, View>>
|
||||
async function viewStateForTx<Input, View>(
|
||||
input: Input,
|
||||
transaction: InteractionTx
|
||||
): Promise<InteractionResult<State, View>>;
|
||||
```
|
||||
|
||||
A version of the viewState method to be used from within the contract's source code. The transaction passed as an argument is the currently processed interaction transaction. The "caller" will be se to the owner of the interaction transaction, that requires to call this method.
|
||||
|
||||
💡 Note! calling "interactRead" from withing contract's source code was not previously possible - this is a new feature.
|
||||
|
||||
- `input` the interaction input
|
||||
- `transaction` interaction transaction
|
||||
- `input` the interaction input
|
||||
- `transaction` interaction transaction
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```typescript
|
||||
const { result } = await contract.viewStateForTx<any, any>({
|
||||
function: "NAME_OF_YOUR_FUNCTION",
|
||||
data: { ... }
|
||||
}, transaction);
|
||||
```
|
||||
```typescript
|
||||
const { result } = await contract.viewStateForTx<any, any>({
|
||||
function: "NAME_OF_YOUR_FUNCTION",
|
||||
data: { ... }
|
||||
}, transaction);
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
@@ -136,28 +147,29 @@ A version of the viewState method to be used from within the contract's source c
|
||||
### `writeInteraction`
|
||||
|
||||
```typescript
|
||||
async function writeInteraction<Input>(input: Input, tags?: Tags, transfer?: ArTransfer): Promise<string>
|
||||
async function writeInteraction<Input>(input: Input, tags?: Tags, transfer?: ArTransfer): Promise<string>;
|
||||
```
|
||||
|
||||
Writes a new "interaction" transaction - ie. such transaction that stores input for the contract.
|
||||
|
||||
- `input` the interaction input
|
||||
- `tags` an array of tags with name/value as objects
|
||||
- `transfer` target and winstonQty for transfer
|
||||
- `input` the interaction input
|
||||
- `tags` an array of tags with name/value as objects
|
||||
- `transfer` target and winstonQty for transfer
|
||||
|
||||
<details>
|
||||
<summary>Example</summary>
|
||||
|
||||
```typescript
|
||||
const result = await contract.writeInteraction({
|
||||
function: "NAME_OF_YOUR_FUNCTION",
|
||||
data: { ... }
|
||||
});
|
||||
```
|
||||
```typescript
|
||||
const result = await contract.writeInteraction({
|
||||
function: "NAME_OF_YOUR_FUNCTION",
|
||||
data: { ... }
|
||||
});
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
|
||||
### 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,24 +1,24 @@
|
||||
# Migration Guide from Arweave's SmartWeave SDK to RedStone SmartContracts SDK
|
||||
# Migration Guide from Arweave's SmartWeave SDK to Warp SDK
|
||||
|
||||
This guide describes <strong>the simplest</strong> way to switch to the new version of SmartWeave. It uses `SmartWeaveNodeFactory` for Node and `SmartWeaveWebFactory` for Web to quickly obtain fully configured, mem-cacheable SmartWeave instance. To see a more detailed explanation of all the core modules visit the [SmartWeave v2 documentation](https://smartweave.docs.redstone.finance/) or check out the [source code.](https://github.com/redstone-finance/redstone-smartweave)
|
||||
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 visit the [Warp documentation](https://smartweave.docs.redstone.finance/) or check out the [source code.](https://github.com/redstone-finance/warp)
|
||||
|
||||
### You can watch this tutorial on YouTube 🎬
|
||||
- [Youtube link](https://www.youtube.com/watch?v=fNjUV7mHFqw)
|
||||
|
||||
[](https://www.youtube.com/watch?v=fNjUV7mHFqw)
|
||||
[](https://www.youtube.com/watch?v=fNjUV7mHFqw)
|
||||
|
||||
### Need help? 🙋♂️
|
||||
Please feel free to contact us [on Discord](https://redstone.finance/discord) if you face any problems.
|
||||
|
||||
## 1. Update dependencies 📦
|
||||
|
||||
#### 1.1 Install smartweave v2
|
||||
#### 1.1 Install Warp
|
||||
```bash
|
||||
# Yarn
|
||||
yarn add redstone-smartweave
|
||||
yarn add warp
|
||||
|
||||
# or NPM
|
||||
npm install redstone-smartweave
|
||||
npm install warp
|
||||
```
|
||||
#### 1.2 Remove smartweave v1
|
||||
If smartweave was installed globally, add `-g` flag to npm or use `yarn global`
|
||||
@@ -33,15 +33,15 @@ npm uninstall smartweave
|
||||
#### 1.3 Replace imports
|
||||
You can import the full API or individual modules.
|
||||
```typescript
|
||||
import * as SmartWeaveSdk from 'redstone-smartweave';
|
||||
import { SmartWeave, Contract, ... } from 'redstone-smartweave';
|
||||
import * as WarpSdk from 'warp';
|
||||
import { Warp, Contract, ... } from 'warp';
|
||||
```
|
||||
|
||||
## 2. Update your implementation 🧑💻
|
||||
### 2.1 Initialize a SmartWeave client
|
||||
### 2.1 Initialize a Warp client
|
||||
```typescript
|
||||
import Arweave from 'arweave';
|
||||
import { SmartWeaveNodeFactory } from 'redstone-smartweave';
|
||||
import { WarpNodeFactory } from 'warp';
|
||||
|
||||
// Create an Arweave instance
|
||||
const arweave = Arweave.init({
|
||||
@@ -52,28 +52,28 @@ const arweave = Arweave.init({
|
||||
logging: false,
|
||||
});
|
||||
|
||||
// Create a SmartWeave client
|
||||
const smartweave = SmartWeaveNodeFactory.memCached(arweave);
|
||||
// Create a Warp client
|
||||
const smartweave = WarpNodeFactory.memCached(arweave);
|
||||
```
|
||||
|
||||
For Web environment you should use `SmartWeaveWebFactory` instead of `SmartWeaveNodeFactory`.
|
||||
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:
|
||||
- [For Web](https://smartweave.docs.redstone.finance/classes/SmartWeaveWebFactory.html)
|
||||
- [For Node.js](https://smartweave.docs.redstone.finance/classes/SmartWeaveNodeFactory.html)
|
||||
|
||||
#### [Optional] Custom modules 🛠
|
||||
Smartweave V2 has a modular architecture, which allows you to connect custom modules to any part of the SmartWeave 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
|
||||
```typescript
|
||||
// Simple connection (allows to read state)
|
||||
const contract = smartweave.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.
|
||||
|
||||
```typescript
|
||||
const contract = smartweave
|
||||
const contract = warp
|
||||
.contract("YOUR_CONTRACT_TX_ID")
|
||||
.connect(jwk) // jwk should be a valid private key (in JSON Web Key format)
|
||||
.setEvaluationOptions({
|
||||
@@ -115,7 +115,7 @@ const result = await contract.writeInteraction({
|
||||
💡 You can read detailed explanation of each contract method [here.](CONTRACT_METHODS.md)
|
||||
|
||||
### [Optional] 2.4 Confgure logging
|
||||
Smartweave V2 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
|
||||
```typescript
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# RedStone SmartContracts SDK
|
||||
# RedStone Warp SDK
|
||||
|
||||
### The issues with original smartweave.js SDK
|
||||
* low performance (unnecessary calls to Arweave http api, no easy option to add caching layer, etc.)
|
||||
|
||||
Reference in New Issue
Block a user