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 : yusufinery #1524

Open
wants to merge 3 commits into
base: task4
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions yusufinery/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEY='INERY_PRIVATE_KEY'
INERY_ACCOUNT='INERY_ACCOUNT'
20 changes: 20 additions & 0 deletions yusufinery/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
35 changes: 35 additions & 0 deletions yusufinery/readme.md
Original file line number Diff line number Diff line change
@@ -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
```
78 changes: 78 additions & 0 deletions yusufinery/solution.mjs
Original file line number Diff line number Diff line change
@@ -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");