From 450663a24d648971cc792083a72c2856ee9db0f2 Mon Sep 17 00:00:00 2001 From: yusufbugra <108667395+asabanoglu@users.noreply.github.com> Date: Wed, 17 May 2023 23:17:31 +0300 Subject: [PATCH 1/3] Add files via upload --- yusufinery/package.json | 20 +++++++++++ yusufinery/solution.mjs | 78 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 yusufinery/package.json create mode 100644 yusufinery/solution.mjs diff --git a/yusufinery/package.json b/yusufinery/package.json new file mode 100644 index 000000000..733994125 --- /dev/null +++ b/yusufinery/package.json @@ -0,0 +1,20 @@ +{ + "name": "taks4", + "version": "1.0.0", + "description": "A sample rpc transaction for inery blockchain", + "main": "./solution.mjs", + "scripts": { + "solution": "node ./solution.mjs" + }, + "author": "yusufinery", + "license": "MIT", + "repository": { + "type": "git", + "url": "" + }, + "homepage": "", + "dependencies": { + "ineryjs": "github:inery-blockchain/ineryjs", + "dotenv": "^16.0.3" + } +} \ No newline at end of file diff --git a/yusufinery/solution.mjs b/yusufinery/solution.mjs new file mode 100644 index 000000000..50e1ab7e4 --- /dev/null +++ b/yusufinery/solution.mjs @@ -0,0 +1,78 @@ +import { Api, JsonRpc, JsSignatureProvider } from 'ineryjs/dist/index.js'; +import * as dotenv from 'dotenv'; +dotenv.config(); + +const url = "http://5.161.181.217:8888"; +const account = process.env.INERY_ACCOUNT; +const private_key = process.env.PRIVATE_KEY; + +const json_rpc = new JsonRpc(url); +const signature = new JsSignatureProvider([private_key]); +const api = new Api({ + rpc: json_rpc, + signatureProvider: signature +}); + +async function sendTransaction(actions) { + try { + const tx = await api.transact({ + actions + }, { broadcast: true, sign: true }); + + console.log("============================================================="); + console.log("================= Transaction Details ======================="); + console.log("============================================================="); + console.log(tx, "\n"); + console.log("Response from contract:", tx.processed.action_traces[0].console); + console.log("\n"); + } catch (error) { + console.log(error); + } +} + +async function create(id, user, data) { + const actions = [ + { + account, + name: "create", + authorization: [ + { + actor, + permission: "active" + } + ], + data: { + id, + user, + data + } + } + ]; + await sendTransaction(actions); +} + +async function destroy(id) { + const actions = [ + { + account, + name: "destroy", + authorization: [ + { + actor, + permission: "active" + } + ], + data: { + id + } + } + ]; + await sendTransaction(actions); +} + +async function main(id, user, data) { + await create(id, user, data); + await destroy(id); +} + +main(1, account, "CRUD Transaction via JSON RPC"); \ No newline at end of file From d55442a3d0cd9869dc4fef46d9a544c01c1b1772 Mon Sep 17 00:00:00 2001 From: yusufbugra <108667395+asabanoglu@users.noreply.github.com> Date: Wed, 17 May 2023 23:18:13 +0300 Subject: [PATCH 2/3] Create .env-example --- yusufinery/.env-example | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 yusufinery/.env-example diff --git a/yusufinery/.env-example b/yusufinery/.env-example new file mode 100644 index 000000000..ab3dcafbc --- /dev/null +++ b/yusufinery/.env-example @@ -0,0 +1,2 @@ +PRIVATE_KEY='INERY_PRIVATE_KEY' +INERY_ACCOUNT='INERY_ACCOUNT' From e19b2dbe7b1edf654ffc9cab16ec9b1221de7fdf Mon Sep 17 00:00:00 2001 From: yusufbugra <108667395+asabanoglu@users.noreply.github.com> Date: Wed, 17 May 2023 23:19:57 +0300 Subject: [PATCH 3/3] Create readme.md --- yusufinery/readme.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 yusufinery/readme.md diff --git a/yusufinery/readme.md b/yusufinery/readme.md new file mode 100644 index 000000000..0a179ff67 --- /dev/null +++ b/yusufinery/readme.md @@ -0,0 +1,35 @@ +### Prerequisite + +- [NodeJS](https://nodejs.org/en/) + +- NPM + + + +### How to run + +Change directory to ```yusufinery``` + +```shell +cd ./yusufinery +``` + +Create .env and edit the variable +PRIVATE_KEY=YOUR PRIVATE KEY +INERY_ACCOUNT=YOUR INERY ACCOUNT + +```shell +nano .env +``` + +Install dependencies + +```shell +npm install +``` + +Run the script + +``` +npm run solution +```