From d7e27289b73a0fee9662b6ecf1fae9466cecfe9c Mon Sep 17 00:00:00 2001 From: AffanJituYA <129447326+AffanJituYA@users.noreply.github.com> Date: Fri, 31 Mar 2023 04:06:11 +0700 Subject: [PATCH] inery task4 affanjitu --- affanjitu/README.md | 46 ++++++++++++++++++++++ affanjitu/package.json | 18 +++++++++ affanjitu/value_contract_tx.mjs | 70 +++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 affanjitu/README.md create mode 100644 affanjitu/package.json create mode 100644 affanjitu/value_contract_tx.mjs diff --git a/affanjitu/README.md b/affanjitu/README.md new file mode 100644 index 000000000..f6dc5e7c6 --- /dev/null +++ b/affanjitu/README.md @@ -0,0 +1,46 @@ +### 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/affanjituya/inery-testnet-faucet-tasks -b task4 +``` +### +### Configuring env vars in +- `NODE_URL=YOUR NODE` +- `PRIV_KEY=YOUR PRIVATE KEY` +- `ACCOUNT=YOUR INERY ACCOUNT` +- `DATA_ID=YOUR DATA ID` Number only + +``` +cd inery-testnet-faucet-tasks/affanjitu +``` +``` +nano .env +``` + +### Install module dependencies + +``` +npm install -g npm +npm install +``` + +## Run the script +``` +npm run push-rpc-inery +``` +or +``` +node ./value_contract_tx.mjs +``` diff --git a/affanjitu/package.json b/affanjitu/package.json new file mode 100644 index 000000000..bc4c70104 --- /dev/null +++ b/affanjitu/package.json @@ -0,0 +1,18 @@ +{ + "name": "inery-task4", + "version": "1.0.0", + "scripts": { + "push-rpc-inery": "node ./value_contract_tx.mjs" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/AffanJituYA/inery-testnet-faucet-tasks.git" + }, + "author": "affanjitu", + "license": "ISC", + "homepage": "https://github.com/AffanJituYA/inery-testnet-faucet-tasks#readme", + "dependencies": { + "ineryjs": "github:inery-blockchain/ineryjs", + "dotenv": "latest" + } +} diff --git a/affanjitu/value_contract_tx.mjs b/affanjitu/value_contract_tx.mjs new file mode 100644 index 000000000..f3f3efe85 --- /dev/null +++ b/affanjitu/value_contract_tx.mjs @@ -0,0 +1,70 @@ +import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs' +import * as dotenv from 'dotenv' +dotenv.config() + +const rpc = new JsonRpc(process.env.NODE_URL) +const signatureProvider = new JsSignatureProvider([process.env.PRIV_KEY]) +const api = new Api({ rpc, signatureProvider }) +const account = process.env.ACCOUNT +const id = 1000 +const data = "INERY JSON-RPC CRUD push transaction" + +await api.getAbi(account, true) + +async function createData() { + try { + const result = await api.transact({ + actions: [api.with(account).as(account).create(id, account, data)] + }) + console.log(result.processed.action_traces[0].act.name) + console.log(result.processed.action_traces[0].console) + console.log(result.processed.action_traces[0]) + } catch (error) { + console.error(error) + } +} + +async function readData() { + try { + const result = await api.transact({ + actions: [api.with(account).as(account).read(id)] + }) + console.log(result.processed.action_traces[0].act.name) + console.log(result.processed.action_traces[0].console) + console.log(result.processed.action_traces[0]) + } catch (error) { + console.error(error) + } +} + +async function updateData() { + try { + const result = await api.transact({ + actions: [api.with(account).as(account).update(id, data)] + }) + console.log(result.processed.action_traces[0].act.name) + console.log(result.processed.action_traces[0].console) + console.log(result.processed.action_traces[0]) + } catch (error) { + console.error(error) + } +} + +async function deleteData() { + try { + const result = await api.transact({ + actions: [api.with(account).as(account).destroy(id)] + }) + console.log(result.processed.action_traces[0].act.name) + console.log(result.processed.action_traces[0].console) + console.log(result.processed.action_traces[0]) + } catch (error) { + console.error(error) + } +} + +createData() +readData() +updateData() +deleteData() +