Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task4 #1516

Open
wants to merge 4 commits into
base: task4
Choose a base branch
from
Open

Task4 #1516

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions README.md

This file was deleted.

30 changes: 30 additions & 0 deletions rizal21/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### 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
99 changes: 99 additions & 0 deletions rizal21/index.mjs
Original file line number Diff line number Diff line change
@@ -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");
20 changes: 20 additions & 0 deletions rizal21/package.json
Original file line number Diff line number Diff line change
@@ -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"
}