diff --git a/wundiyasuka/Config-Inery.js b/wundiyasuka/Config-Inery.js new file mode 100644 index 000000000..7b2f5cccc --- /dev/null +++ b/wundiyasuka/Config-Inery.js @@ -0,0 +1,17 @@ +import { Api, JsonRpc, JsSignatureProvider } from "ineryjs"; +import dotenv from "dotenv"; +dotenv.config(); + +const url = "http://74.208.122.244:8888"; + +const json_rpc = new JsonRpc(url); +const account = "wundiyasuka"; +const actor = "wundiyasuka"; +const signature = new JsSignatureProvider([process.env.PRIVATE_KEY]); + +const Userapi = new Api({ + rpc: json_rpc, + signatureProvider: signature, +}); + +export { Userapi, account, actor }; diff --git a/wundiyasuka/Destroy-Transaction.js b/wundiyasuka/Destroy-Transaction.js new file mode 100644 index 000000000..5f4772500 --- /dev/null +++ b/wundiyasuka/Destroy-Transaction.js @@ -0,0 +1,31 @@ +import { Userapi, account, actor } from "./config-inery.js"; + +const Destroy = async (id) => { + try { + const hashId = await Userapi.transact( + { + actions: [ + { + account, + name: "destroy", + authorization: [ + { + actor, + permission: "active", + }, + ], + data: { + id, + }, + }, + ], + }, + { broadcast: true, sign: true } + ); + console.log(hashId); + } catch (error) { + console.log(error); + } +}; + +Destroy(1050); diff --git a/wundiyasuka/Package.json b/wundiyasuka/Package.json new file mode 100644 index 000000000..aec6ae2bf --- /dev/null +++ b/wundiyasuka/Package.json @@ -0,0 +1,39 @@ +{ + "name": "wundiyasuka", + "version": "1.0.0", + "description": "Inery RPC API", + "main": "index.js", + "scripts": { + "doc": "jsdoc -c jsdoc.json", + "generate-docs": "jsdoc --configure jsdoc.json --verbose", + "build-web": "webpack --config webpack.config.js" + }, + "author": "wundiyasuka", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/WundiNode/inery-testnet-faucet-tasks.git" + }, + "homepage": "https://github.com/WundiNode/inery-testnet-faucet-tasks.git", + "dependencies": { + "bn.js": "^5.2.0", + "elliptic": "^6.5.4", + "hash.js": "^1.1.7", + "node-fetch": "^2.6.7", + "pako": "^2.0.3" + }, + "devDependencies": { + "browser-fs-access": "^0.31.0", + "browserify": "^17.0.0", + "buffer": "^6.0.3", + "clean-jsdoc-theme": "^4.1.7", + "crypto-browserify": "^3.12.0", + "https-browserify": "^1.0.0", + "jsdoc": "^3.5.5", + "node-util": "^0.0.1", + "stream-http": "^3.2.0", + "url": "^0.11.0", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + } + } \ No newline at end of file diff --git a/wundiyasuka/README.md b/wundiyasuka/README.md new file mode 100644 index 000000000..0d05a5127 --- /dev/null +++ b/wundiyasuka/README.md @@ -0,0 +1,50 @@ +## RPC API Inery Task 4 + +### Instal curl - Run command +``` +sudo apt-get install curl +``` + +### Install NodeJS & NPM + +- OS [Windows](https://nodejs.org/en/download/) +- OS Linux: +``` +curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\ +sudo apt-get install -y nodejs +``` + + + +## Running Command for Inery Task 4 + +**1. First change directory to `wundiyasuka`** + +```shell +cd ./wundiyasuka +``` + + +**2. Install dependencies** + +```shell +npm install +``` + +**3. Create & edit `.env` file** +``` +cp .env-sample .env +``` + + +**4. Run the script** + +``` +npm run solution +``` + +**5. Run script for transaction** + +``` +npm run push +``` \ No newline at end of file diff --git a/wundiyasuka/Transaction-Inery.js b/wundiyasuka/Transaction-Inery.js new file mode 100644 index 000000000..4f1bfb8c0 --- /dev/null +++ b/wundiyasuka/Transaction-Inery.js @@ -0,0 +1,67 @@ +import { Userapi, account, actor } from "./config-inery.js"; + +const Create = async (id, user, data) => { + try { + const hashtx = await Userapi.transact( + { + actions: [ + { + account, + name: "create", + authorization: [ + { + actor, + permission: "active", + }, + ], + data: { + id, + user, + data, + }, + }, + ], + }, + { broadcast: true, sign: true } + ); + + console.log(hashtx); + } catch (err) { + console.log(err); + } +}; + +const Read = async (id) => { + try { + const hashId = await Userapi.transact( + { + actions: [ + { + account, + name: "read", + authorization: [ + { + actor, + permission: "active", + }, + ], + data: { + id, + }, + }, + ], + }, + { broadcast: true, sign: true } + ); + console.log(hashId); + } catch (error) { + console.log(error); + } +}; + +const Push = async (HasId, user, data) => { + await Create(HasId, user, data); + await Read(HasId); +}; + +Push(10543230, account, "inery task4");