From 57bf58dc75493e16f1bccacfc5387c631c6c7695 Mon Sep 17 00:00:00 2001 From: Leonidas Conde <80922146+LeonardoDizConde@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:23:59 -0300 Subject: [PATCH] CU-86dt0ndwq - Improvements on NeonDappkit docs --- README.md | 39 ++++++++++++------ .../main_2024-04-16-16-14.json | 11 +++++ .../neon-dappkit/main_2024-04-16-16-14.json | 11 +++++ packages/neon-dappkit-types/README.md | 41 ++++++++++++------- packages/neon-dappkit/NEON-EVENT-LISTENER.md | 2 +- packages/neon-dappkit/NEON-INVOKER.md | 6 +-- packages/neon-dappkit/NEON-SIGNER.md | 2 +- packages/neon-dappkit/README.md | 41 +++++++++++-------- 8 files changed, 105 insertions(+), 48 deletions(-) create mode 100644 common/changes/@cityofzion/neon-dappkit-types/main_2024-04-16-16-14.json create mode 100644 common/changes/@cityofzion/neon-dappkit/main_2024-04-16-16-14.json diff --git a/README.md b/README.md index fb997f4..c8ae0a2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ React-Native Apps to the Neo3 Blockchain. > [WalletConnectSDK](https://github.com/CityOfZion/wallet-connect-sdk) uses Neon-DappKit Types, so you can easily swap between Neon-DappKit implementation and WalletConnectSDK on the fly and reuse code, check the -[guide](/packages/neon-dappkit/WALLET-CONNECT.md). +[guide](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/WALLET-CONNECT.md). ## Installation ```sh @@ -41,31 +41,44 @@ export default defineConfig({ ## Getting Started Neon-Dappkit has 4 main components: -- [NeonInvoker](/packages/neon-dappkit/NEON-INVOKER.md): SmartContract Invocation Tool. -- [NeonParser](/packages/neon-dappkit/NEON-PARSER.md): Powerful Parser for Neo3 Types. -- [NeonSigner](/packages/neon-dappkit/NEON-SIGNER.md): Signs, Verifies, Encrypts and Decrypts data. -- [NeonEventListener](/packages/neon-dappkit/NEON-EVENT-LISTENER.md): Listen to events from the Neo3 Blockchain. +- [NeonInvoker](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-INVOKER.md): SmartContract Invocation Tool. +- [NeonParser](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-PARSER.md): Powerful Parser for Neo3 Types. +- [NeonSigner](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-SIGNER.md): Signs, Verifies, Encrypts and Decrypts data. +- [NeonEventListener](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-EVENT-LISTENER.md): Listen to events from the Neo3 Blockchain. + +Check out some examples in [examples folder](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/) ## Quick Example ```ts -import { NeonInvoker, NeonParser } from "@CityOfZion/neon-dappkit"; +import { NeonInvoker, NeonParser, TypeChecker } from '@CityOfZion/neon-dappkit' +import {ContractInvocationMulti} from '@cityofzion/neon-dappkit-types' const invoker = await NeonInvoker.init({ rpcAddress: NeonInvoker.TESTNET, }) -const rawResp = await invoker.testInvoke({ +const invocation: ContractInvocationMulti = { invocations: [ { - scriptHash: '0x123456', - operation: 'myMethod', - args: [123, 'Test'].map(NeonParser.formatRpcArgument) - }, + scriptHash: '0x309b6b2e0538fe4095ecc48e81bb4735388432b5', + operation: 'getMetaData', + args: [ + { + type: 'Hash160', + value: '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5' + } + ] + } ], -}) +} + +const testInvokeResult = await invoker.testInvoke(invocation) -const resp = NeonParser.parseRpcResponse(rawResp.stack[0]) +console.log(`Invocation state returned: ${testInvokeResult.state}`) +console.log(`Estimated GAS consumed on involke: ${testInvokeResult.gasconsumed} GAS`) // Using testInvoke ensures zero GAS consumption, unlike invokeFunction. +console.log(`Contract method returned a map: ${TypeChecker.isStackTypeMap(testInvokeResult.stack[0])}`) +console.log(`Contract method data returned: ${JSON.stringify(NeonParser.parseRpcResponse(testInvokeResult.stack[0]), null, 2)}`) ``` diff --git a/common/changes/@cityofzion/neon-dappkit-types/main_2024-04-16-16-14.json b/common/changes/@cityofzion/neon-dappkit-types/main_2024-04-16-16-14.json new file mode 100644 index 0000000..b0d2059 --- /dev/null +++ b/common/changes/@cityofzion/neon-dappkit-types/main_2024-04-16-16-14.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Improvements on NeonDappkit docs", + "type": "none", + "packageName": "@cityofzion/neon-dappkit-types" + } + ], + "packageName": "@cityofzion/neon-dappkit-types", + "email": "80922146+LeonardoDizConde@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@cityofzion/neon-dappkit/main_2024-04-16-16-14.json b/common/changes/@cityofzion/neon-dappkit/main_2024-04-16-16-14.json new file mode 100644 index 0000000..bafe218 --- /dev/null +++ b/common/changes/@cityofzion/neon-dappkit/main_2024-04-16-16-14.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Improvements on NeonDappkit docs", + "type": "none", + "packageName": "@cityofzion/neon-dappkit" + } + ], + "packageName": "@cityofzion/neon-dappkit", + "email": "80922146+LeonardoDizConde@users.noreply.github.com" +} \ No newline at end of file diff --git a/packages/neon-dappkit-types/README.md b/packages/neon-dappkit-types/README.md index 94295e8..28658c9 100644 --- a/packages/neon-dappkit-types/README.md +++ b/packages/neon-dappkit-types/README.md @@ -11,7 +11,7 @@ # Neon-DappKit -Neon-DappKit is the easiest way to build a dApp on Neo3. Suitable to connect Web Applications, Off-chain JS Servers and +Neon-DappKit is the easiest way to build a dApp on Neo3. Suitable to connect Web Applications, Off-chain JS Servers and React-Native Apps to the Neo3 Blockchain. > [WalletConnectSDK](https://github.com/CityOfZion/wallet-connect-sdk) uses Neon-DappKit Types, so you can easily swap @@ -20,7 +20,7 @@ between Neon-DappKit implementation and WalletConnectSDK on the fly and reuse co ## Installation ```sh -npm i @CityOfZion/neon-dappkit +npm i @cityofzion/neon-dappkit-types ```
@@ -41,31 +41,44 @@ export default defineConfig({ ## Getting Started Neon-Dappkit has 4 main components: -- [NeonInvoker](/packages/neon-dappkit/NEON-INVOKER.md): SmartContract Invocation Tool. -- [NeonParser](/packages/neon-dappkit/NEON-PARSER.md): Powerful Parser for Neo3 Types. -- [NeonSigner](/packages/neon-dappkit/NEON-SIGNER.md): Signs, Verifies, Encrypts and Decrypts data. -- [NeonEventListener](/packages/neon-dappkit/NEON-EVENT-LISTENER.md): Listen to events from the Neo3 Blockchain. +- [NeonInvoker](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-INVOKER.md): SmartContract Invocation Tool. +- [NeonParser](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-PARSER.md): Powerful Parser for Neo3 Types. +- [NeonSigner](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-SIGNER.md): Signs, Verifies, Encrypts and Decrypts data. +- [NeonEventListener](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-EVENT-LISTENER.md): Listen to events from the Neo3 Blockchain. + +Check out some examples in [examples folder](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/) ## Quick Example ```ts -import { NeonInvoker, NeonParser } from "@CityOfZion/neon-dappkit"; +import { NeonInvoker, NeonParser, TypeChecker } from '@CityOfZion/neon-dappkit' +import {ContractInvocationMulti} from '@cityofzion/neon-dappkit-types' const invoker = await NeonInvoker.init({ rpcAddress: NeonInvoker.TESTNET, }) -const rawResp = await invoker.testInvoke({ +const invocation: ContractInvocationMulti = { invocations: [ { - scriptHash: '0x123456', - operation: 'myMethod', - args: [123, 'Test'].map(NeonParser.formatRpcArgument) - }, + scriptHash: '0x309b6b2e0538fe4095ecc48e81bb4735388432b5', + operation: 'getMetaData', + args: [ + { + type: 'Hash160', + value: '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5' + } + ] + } ], -}) +} + +const testInvokeResult = await invoker.testInvoke(invocation) -const resp = NeonParser.parseRpcResponse(rawResp.stack[0]) +console.log(`Invocation state returned: ${testInvokeResult.state}`) +console.log(`Estimated GAS consumed on involke: ${testInvokeResult.gasconsumed} GAS`) // Using testInvoke ensures zero GAS consumption, unlike invokeFunction. +console.log(`Dapp method returned a map: ${TypeChecker.isStackTypeMap(testInvokeResult.stack[0])}`) +console.log(`Dapp method data returned: ${JSON.stringify(NeonParser.parseRpcResponse(testInvokeResult.stack[0]), null, 2)}`) ``` diff --git a/packages/neon-dappkit/NEON-EVENT-LISTENER.md b/packages/neon-dappkit/NEON-EVENT-LISTENER.md index d714d37..c3e6db3 100644 --- a/packages/neon-dappkit/NEON-EVENT-LISTENER.md +++ b/packages/neon-dappkit/NEON-EVENT-LISTENER.md @@ -68,4 +68,4 @@ eventListener.confirmTransaction( For more details on the methods signature, check the auto-generated [Docs](https://htmlpreview.github.io/?https://raw.githubusercontent.com/CityOfZion/neon-dappkit/master/packages/neon-dappkit-types/docs/interfaces/Neo3EventListener.html) -and the [Source Code](./src/NeonEventListener.ts). \ No newline at end of file +and the [Source Code](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/src/NeonEventListener.ts). \ No newline at end of file diff --git a/packages/neon-dappkit/NEON-INVOKER.md b/packages/neon-dappkit/NEON-INVOKER.md index cefbe15..1c41836 100644 --- a/packages/neon-dappkit/NEON-INVOKER.md +++ b/packages/neon-dappkit/NEON-INVOKER.md @@ -8,9 +8,9 @@ To persist changes to the blockchain or sign the transactions you should pass an `Account` from `@cityofzion/neon-js`. Check the example: ```ts import { NeonInvoker } from '@cityofzion/neon-dappkit' -import { default as Neon } from '@cityofzion/neon-js' +import * as Neon from '@cityofzion/neon-js' -const account = new Neon.wallet.account('3bd06d95e9189385851aa581d182f25de34af759cf7f883af57030303ded52b8') +const account = new Neon.wallet.Account('3bd06d95e9189385851aa581d182f25de34af759cf7f883af57030303ded52b8') const invoker = await NeonInvoker.init({ rpcAddress: NeonInvoker.MAINNET, @@ -254,4 +254,4 @@ const txId = await invokerOwner.invokeFunction(builtTransaction) For more details on the methods signature, check the auto-generated [Docs](https://htmlpreview.github.io/?https://raw.githubusercontent.com/CityOfZion/neon-dappkit/master/packages/neon-dappkit-types/docs/interfaces/Neo3Invoker.html), -the [Unit Tests](./src/NeonInvoker.spec.ts) and the [Source Code](./src/NeonInvoker.ts). \ No newline at end of file +the [Unit Tests](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/src/NeonInvoker.spec.ts) and the [Source Code](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/src/NeonInvoker.ts). \ No newline at end of file diff --git a/packages/neon-dappkit/NEON-SIGNER.md b/packages/neon-dappkit/NEON-SIGNER.md index c6777a6..39f18ec 100644 --- a/packages/neon-dappkit/NEON-SIGNER.md +++ b/packages/neon-dappkit/NEON-SIGNER.md @@ -71,4 +71,4 @@ is the correct one. For more details on the methods signature, check the auto-generated [Docs](https://htmlpreview.github.io/?https://raw.githubusercontent.com/CityOfZion/neon-dappkit/master/packages/neon-dappkit-types/docs/interfaces/Neo3Signer.html), -the [Unit Tests](./src/NeonSigner.spec.ts) and the [Source Code](./src/NeonSigner.ts). \ No newline at end of file +the [Unit Tests](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/src/NeonSigner.spec.ts) and the [Source Code](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/src/NeonSigner.ts). \ No newline at end of file diff --git a/packages/neon-dappkit/README.md b/packages/neon-dappkit/README.md index 94295e8..426dc57 100644 --- a/packages/neon-dappkit/README.md +++ b/packages/neon-dappkit/README.md @@ -11,16 +11,16 @@ # Neon-DappKit -Neon-DappKit is the easiest way to build a dApp on Neo3. Suitable to connect Web Applications, Off-chain JS Servers and +Neon-DappKit is the easiest way to build a dApp on Neo3. Suitable to connect Web Applications, Off-chain JS Servers and React-Native Apps to the Neo3 Blockchain. > [WalletConnectSDK](https://github.com/CityOfZion/wallet-connect-sdk) uses Neon-DappKit Types, so you can easily swap between Neon-DappKit implementation and WalletConnectSDK on the fly and reuse code, check the -[guide](/packages/neon-dappkit/WALLET-CONNECT.md). +[guide](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/WALLET-CONNECT.md). ## Installation ```sh -npm i @CityOfZion/neon-dappkit +npm i @cityofzion/neon-dappkit ```
@@ -41,31 +41,40 @@ export default defineConfig({ ## Getting Started Neon-Dappkit has 4 main components: -- [NeonInvoker](/packages/neon-dappkit/NEON-INVOKER.md): SmartContract Invocation Tool. -- [NeonParser](/packages/neon-dappkit/NEON-PARSER.md): Powerful Parser for Neo3 Types. -- [NeonSigner](/packages/neon-dappkit/NEON-SIGNER.md): Signs, Verifies, Encrypts and Decrypts data. -- [NeonEventListener](/packages/neon-dappkit/NEON-EVENT-LISTENER.md): Listen to events from the Neo3 Blockchain. +- [NeonInvoker](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-INVOKER.md): SmartContract Invocation Tool. +- [NeonParser](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-PARSER.md): Powerful Parser for Neo3 Types. +- [NeonSigner](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-SIGNER.md): Signs, Verifies, Encrypts and Decrypts data. +- [NeonEventListener](https://github.com/CityOfZion/neon-dappkit/blob/main/packages/neon-dappkit/NEON-EVENT-LISTENER.md): Listen to events from the Neo3 Blockchain. + +Check out some examples in [examples folder](https://github.com/CityOfZion/neon-dappkit/packages/neon-dappkit/) ## Quick Example ```ts -import { NeonInvoker, NeonParser } from "@CityOfZion/neon-dappkit"; +import { NeonInvoker, NeonParser, TypeChecker } from '@CityOfZion/neon-dappkit' const invoker = await NeonInvoker.init({ rpcAddress: NeonInvoker.TESTNET, }) -const rawResp = await invoker.testInvoke({ +const testInvokeResult = await invoker.testInvoke({ invocations: [ { - scriptHash: '0x123456', - operation: 'myMethod', - args: [123, 'Test'].map(NeonParser.formatRpcArgument) - }, + scriptHash: '0x309b6b2e0538fe4095ecc48e81bb4735388432b5', + operation: 'getMetaData', + args: [ + { + type: 'Hash160', + value: '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5' + } + ] + } ], }) -const resp = NeonParser.parseRpcResponse(rawResp.stack[0]) -``` - +console.log(`Invocation state returned: ${testInvokeResult.state}`) +console.log(`Estimated GAS consumed on involke: ${testInvokeResult.gasconsumed} GAS`) // Using testInvoke ensures zero GAS consumption, unlike invokeFunction. +console.log(`Dapp method returned a map: ${TypeChecker.isStackTypeMap(testInvokeResult.stack[0])}`) +console.log(`Dapp method data returned: ${JSON.stringify(NeonParser.parseRpcResponse(testInvokeResult.stack[0]), null, 2)}`) +``` \ No newline at end of file