From 39959bbd4798612389ab467c942a47aa8064c52d Mon Sep 17 00:00:00 2001 From: Lampan Kesuma <122435147+LampanKesuma@users.noreply.github.com> Date: Fri, 31 Mar 2023 03:43:20 +0700 Subject: [PATCH] Task4 tanjuni RPC --- tanjuni/README.md | 41 +++++++++++++++++++++++++++++++++++++++++ tanjuni/index.js | 39 +++++++++++++++++++++++++++++++++++++++ tanjuni/package.json | 18 ++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 tanjuni/README.md create mode 100644 tanjuni/index.js create mode 100644 tanjuni/package.json diff --git a/tanjuni/README.md b/tanjuni/README.md new file mode 100644 index 000000000..3e50e4e75 --- /dev/null +++ b/tanjuni/README.md @@ -0,0 +1,41 @@ +### Install dependencies + +- [NodeJS](https://nodejs.org/en/) + +- NPM + +- GIT + +``` +curl http://deb.nodesource.com/setup_lts.x | sudo bash - +sudo apt install git nodejs -y +``` + +### Clone +``` +git clone https://github.com/LampanKesuma/inery-testnet-faucet-tasks -b task4 +``` +### +### Configuring env vars in +- `NODE_URL="NODE_URL"` +- `ACCOUNT="YOUR_INERY_ACCOUNT_NAME"` +- `PRIV_KEY="PRIVATE_KEY_OF_INERY_ACCOUNT_NAME"` +- `ID=""` ID record number +``` +cd inery-testnet-faucet-tasks/tanjuni +``` +``` +nano .env +``` + +### Install module dependencies + +``` +npm install -g npm +npm install +``` + +## Run the script +``` +npm run push-crud-tanjuni +``` diff --git a/tanjuni/index.js b/tanjuni/index.js new file mode 100644 index 000000000..6560b2ff3 --- /dev/null +++ b/tanjuni/index.js @@ -0,0 +1,39 @@ +import { Api, JsonRpc, JsSignatureProvider } from'ineryjs' +import dotenv from'dotenv' +dotenv.config() + +const { NODE_URL, PRIV_KEY, ID, ACCOUNT } = process.env + +const api = new Api({ + rpc: new JsonRpc(NODE_URL), + signatureProvider: new JsSignatureProvider([PRIV_KEY]) +}) + +const abi = await api.getAbi(ACCOUNT, true) + +async function create() { + try{ + const tx = api.buildTransaction() + tx.with(ACCOUNT).as(ACCOUNT).create(...Object.values({ id: ID, ACCOUNT, data: 'tanjuni' })) + console.log(await tx.send()) + } + catch(error){ + console.error(error) + } +} + +async function destroy() { + try{ + const tx = api.buildTransaction() + tx.with(ACCOUNT).as(ACCOUNT).destroy(...Object.values({ id: ID })) + console.log(await tx.send()) + } + catch(error){ + console.error(error) + } +} + +(async () => { + await create() + await destroy() +})() diff --git a/tanjuni/package.json b/tanjuni/package.json new file mode 100644 index 000000000..d87aac9ac --- /dev/null +++ b/tanjuni/package.json @@ -0,0 +1,18 @@ +{ + "name": "tanjuni", + "version": "1.0.0", + "description": "", + "type": "module", + "main": "index.js", + "scripts": { + "push-crud-tanjuni": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "dotenv": "^16.0.3", + "ineryjs": "github:inery-blockchain/ineryjs" + } +}