From 68893659c9bb27817099c7bacd662f270892b963 Mon Sep 17 00:00:00 2001 From: rizaltjr <79238915+rizaltjr@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:33:51 +0700 Subject: [PATCH 1/4] Add files via upload --- README.md | 50 +++++++++++++++----------- index.mjs | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 20 +++++++++++ 3 files changed, 149 insertions(+), 20 deletions(-) create mode 100644 index.mjs create mode 100644 package.json diff --git a/README.md b/README.md index 7ffddb979..5b789f1b2 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,30 @@ -# Task 4 RPC API push transaction - -To complete task 4, you need to follow these instructions: - - FIRST - Clone the Git repository for the project. - - SECOND - Add a new directory using your account name as the directory name. - - THIRD - Inside directory, add your software solution for task 4, which should be a solution for pushing transactions with the RPC API on the Inery testnet blockchain. - - FOURTH - Create a merge request to submit your work for review. - -If your solution is successful and works correctly, it will be accepted and task 4 will be approved - -NOTE: - It is important to follow the instructions given above and make sure your solution meets the requirements. Also make sure you test your code before submitting it for review to ensure that it works correctly. + ### How to run + +Clone repo + +```shell +git clone https://github.com/rizaltjr/inery-testnet-faucet-tasks -b task4 +``` + +Change directory rizal21 + +```shell +cd ~/inery-testnet-faucet-tasks/rizal21 +``` + +Install dependencies and edit file index.mjs + +```shell +npm install +``` + +```shell +nano index.mjs +``` + +Run the script + +``` +npm run push +``` +DONE diff --git a/index.mjs b/index.mjs new file mode 100644 index 000000000..af1f359fe --- /dev/null +++ b/index.mjs @@ -0,0 +1,99 @@ +import { Api, JsonRpc, JsSignatureProvider } from "ineryjs"; +import dotenv from "dotenv"; +import ora from "ora"; +import chalk from "chalk"; +dotenv.config(); + +const ineryUrl = "http://your-ip:8888"; // ganti dengan alamat IP VPS node Anda +const ineryAccount = "rizal"; // ganti dengan nama akun inery Anda +const ineryActor = "rizal"; // ganti dengan nama inery Anda +const ineryPrivateKey = "your-private-key"; // ganti dengan kunci privat Anda + +const signatureProvider = new JsSignatureProvider([ineryPrivateKey]); +const rpc = new JsonRpc(ineryUrl); +const api = new Api({ rpc, signatureProvider }); + +const createHashTransaction = async (id, user, data) => { + const Hashdata = { id, user, data }; + try { + const tx = await api.transact( + { + actions: [ + { + account: ineryAccount, + name: "create", + authorization: [ + { + actor: ineryActor, + permission: "active", + }, + ], + data: { + ...Hashdata, + }, + }, + ], + }, + { broadcast: true, sign: true } + ); + + console.log(tx, "\n"); + console.log("\nResponsed data:", tx.processed.action_traces[0].console); + } catch (err) { + console.log(err); + } +}; + +const destroyHashTransaction = async (id) => { + try { + const destroyTx = await api.transact( + { + actions: [ + { + account: ineryAccount, + name: "destroy", + authorization: [ + { + actor: ineryActor, + permission: "active", + }, + ], + data: { + id, + }, + }, + ], + }, + { broadcast: true, sign: true } + ); + + console.log(chalk.red("Record destroyed\n\n")); + console.log(destroyTx, "\n"); + console.log("responses: \n", destroyTx.processed.action_traces[0].console); + } catch (err) { + console.log(err); + } +}; + +const pushHashTransaction = async (dataId, user, data) => { + const spinner = ora({ + text: "Processing transaction...", + spinner: { + interval: 150, + frames: ["◐", "◓", "◑", "◒"], + }, + }).start(); + + try { + await createHashTransaction(dataId, user, data); + await destroyHashTransaction(dataId); + + spinner.stop(); + console.log(chalk.green("Transaction completed!")); + } catch (err) { + spinner.stop(); + console.log(chalk.red(err)); + } +}; + +pushHashTransaction(1282, ineryAccount, "Thank You"); diff --git a/package.json b/package.json new file mode 100644 index 000000000..da438c079 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "task_4_done_successful", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "commonjs", + "scripts": { + "push": "node ./index.mjs" + }, + "homepage": "https://github.com/rizaltjr/inery-testnet-faucet-tasks", + "dependencies": { + "dotenv": "^16.0.3", + "ineryjs": "github:inery-blockchain/ineryjs", + "ora": "^5.4.1", + "chalk": "^4.1.2" + }, + "keywords": [], + "author": "rizal21", + "license": "ISC" +} From 08e0284147888522c63be2f514dcaf8a479d3d97 Mon Sep 17 00:00:00 2001 From: rizaltjr <79238915+rizaltjr@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:34:26 +0700 Subject: [PATCH 2/4] Rename package.json to rizal21/package.json --- package.json => rizal21/package.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename package.json => rizal21/package.json (100%) diff --git a/package.json b/rizal21/package.json similarity index 100% rename from package.json rename to rizal21/package.json From e03d6a18b16bd2c49c4363e368f4104680d5e79d Mon Sep 17 00:00:00 2001 From: rizaltjr <79238915+rizaltjr@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:34:51 +0700 Subject: [PATCH 3/4] Rename index.mjs to rizal21/index.mjs --- index.mjs => rizal21/index.mjs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename index.mjs => rizal21/index.mjs (100%) diff --git a/index.mjs b/rizal21/index.mjs similarity index 100% rename from index.mjs rename to rizal21/index.mjs From cd1d5be2745552f58c6b7988e7d3dc92a7314be2 Mon Sep 17 00:00:00 2001 From: rizaltjr <79238915+rizaltjr@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:35:15 +0700 Subject: [PATCH 4/4] Rename README.md to rizal21/README.md --- README.md => rizal21/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => rizal21/README.md (100%) diff --git a/README.md b/rizal21/README.md similarity index 100% rename from README.md rename to rizal21/README.md