-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
726e653
commit e400ed2
Showing
3 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## Prerequisite | ||
|
||
### Instal curl | ||
``` | ||
sudo apt-get install curl | ||
``` | ||
|
||
### NodeJS & NPM | ||
- [Windows](https://nodejs.org/en/download/) Included NPM packages | ||
- Linux: | ||
``` | ||
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\ | ||
sudo apt-get install -y nodejs | ||
``` | ||
|
||
|
||
|
||
## How to run? | ||
|
||
**1. Change directory to `aprameth`** | ||
|
||
```shell | ||
cd ./aprameth | ||
``` | ||
|
||
|
||
**2. Install dependencies** | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
**3. Create & edit `.env` file** | ||
``` | ||
cp .env-sample .env | ||
``` | ||
|
||
|
||
**4. Run the script** | ||
|
||
``` | ||
npm run solution | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "aprameth-rpc-transaction", | ||
"version": "1.0.0", | ||
"description": "A sample RPC API push transaction on Inery blockchain", | ||
"main": "./solution.mjs", | ||
"scripts": { | ||
"solution": "node ./solution.mjs" | ||
}, | ||
"author": "DiscoverMyself", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/DiscoverMyself/inery-testnet-faucet-tasks" | ||
}, | ||
"homepage": "https://github.com/DiscoverMyself/inery-testnet-faucet-tasks", | ||
"dependencies": { | ||
"ineryjs": "github:inery-blockchain/ineryjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js' | ||
const url = process.env.NODE_URL | ||
|
||
const json_rpc = new JsonRpc(url) | ||
const private_key = process.env.PRIVATE_KEY; | ||
|
||
const account = process.env.INERY_ACCOUNT | ||
const actor = process.env.INERY_ACCOUNT | ||
const signature = new JsSignatureProvider([private_key]); | ||
|
||
const api = new Api({ | ||
rpc: json_rpc, | ||
signatureProvider: signature | ||
}) | ||
|
||
async function create(id, user, data){ | ||
try{ | ||
const tx = await api.transact({ | ||
actions:[ | ||
{ | ||
account, | ||
name:"create", | ||
authorization:[ | ||
{ | ||
actor, | ||
permission:"active" | ||
} | ||
], | ||
data:{ | ||
id, user, data | ||
} | ||
} | ||
] | ||
},{broadcast:true,sign:true}) | ||
|
||
|
||
console.log("=======================================================================") | ||
console.log("===================== CREATE 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 read(id){ | ||
try{ | ||
const tx = await api.transact({ | ||
actions:[ | ||
{ | ||
account, | ||
name:"read", | ||
authorization:[ | ||
{ | ||
actor, | ||
permission:"active" | ||
} | ||
], | ||
data:{ | ||
id | ||
} | ||
} | ||
] | ||
},{broadcast:true,sign:true}) | ||
|
||
console.log("=======================================================================") | ||
console.log("===================== READ 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 update(id, data){ | ||
try{ | ||
const tx = await api.transact({ | ||
actions:[ | ||
{ | ||
account, | ||
name:"update", | ||
authorization:[ | ||
{ | ||
actor, | ||
permission:"active" | ||
} | ||
], | ||
data:{ | ||
id, data | ||
} | ||
} | ||
] | ||
},{broadcast:true,sign:true}) | ||
|
||
|
||
console.log("=======================================================================") | ||
console.log("===================== UPDATE 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 destroy(id){ | ||
try{ | ||
const tx = await api.transact({ | ||
actions:[ | ||
{ | ||
account, | ||
name:"destroy", | ||
authorization:[ | ||
{ | ||
actor, | ||
permission:"active" | ||
} | ||
], | ||
data:{ | ||
id | ||
} | ||
} | ||
] | ||
},{broadcast:true,sign:true}) | ||
|
||
|
||
console.log("=======================================================================") | ||
console.log("===================== DESTROY 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 main(id, user, data){ | ||
await create(id, user, data) | ||
await read(id) | ||
await update(id, data) | ||
await destroy(id) | ||
} | ||
|
||
main(1, account, "CRUD Transaction via JSON RPC") |