From 22bd6806f19e8a7a0b29c0ab46fc8b511bfa5959 Mon Sep 17 00:00:00 2001 From: Asia Date: Mon, 2 Jan 2023 13:16:44 +0100 Subject: [PATCH] docs: smartweave global (#308) --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/README.md b/README.md index f03365d..bd22279 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ If you are interested in the main assumptions for Warp ecosystem as well as its - [Internal writes](#internal-writes) - [UnsafeClient](#unsafeclient) - [Cache](#cache) + - [SmartWeave Global API](#smartweave-global-api) - [CLI](#cli) - [Examples](#examples) - [Migrations](#migrations) @@ -584,6 +585,59 @@ You can also supply your own implementation of the `SortKeyCache` interface and In order to use custom implementation call either `useStateCache` or `useContractCache` on `warp` instance. An example - LMDB - implementation is available [here](https://github.com/warp-contracts/warp-contracts-lmdb#warp-contracts-lmdb-cache). +### SmartWeave Global API + +All contracts have access to a global object `SmartWeave`. It provides access to additional API for getting further information or using utility and crypto functions from inside the contracts execution. It also allows to interact with other contracts and read other contracts states. + +List of available options: + +* transaction informations: + - SmartWeave.transaction.id + - SmartWeave.transaction.owner + - SmartWeave.transaction.tags + - SmartWeave.transaction.quantity + - SmartWeave.transaction.reward + +* contract + - SmartWeave.contract.id + - SmartWeave.contract.owner + +* contracts + - readContractState(contractId: string) + - viewContractState(contractId: string, input: any) + - write(contractId: string, input: any) + - refreshState() + +* block informations: + - SmartWeave.block.height + - SmartWeave.block.timestamp + - SmartWeave.block.indep_hash + +* Arweave utils + - SmartWeave.arweave.utils + - SmartWeave.arweave.crypto + - SmartWeave.arweave.wallets + - SmartWeave.arweave.ar + +* potentially non-deterministic full Arweave client: + - SmartWeave.unsafeClient + +* evaluation options + - SmartWeave.evaluationOptions + +* VRF + - SmartWeave.vrf.data + - SmartWeave.vrf.value + - SmartWeave.vrf.randomInt(maxValue: number) + +* other + - SmartWeave.useGas(gas: number) + - SmartWeave.getBalance(address: string, height?: number) + - SmartWeave.gasUsed + - SmartWeave.gasLimit + +* extensions - additional `SmartWeave` options which can be for example injected through dedicated plugins (an example of such in [`warp-contracts-plugins` repository](https://github.com/warp-contracts/warp-contracts-plugins)). + ### CLI A dedicated CLI which eases the process of using main methods of the Warp SDK library has been created. Please refer to [`warp-contracts-cli` npm page](https://www.npmjs.com/package/warp-contracts-cli) for more details.