├── aprameth ├── package.json ├── README.md └── solution.mjs └── README.md /aprameth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aprameth-rpc-transaction", 3 | "version": "1.0.0", 4 | "description": "A sample RPC API push transaction on Inery blockchain", 5 | "main": "./solution.mjs", 6 | "scripts": { 7 | "solution": "node ./solution.mjs" 8 | }, 9 | "author": "DiscoverMyself", 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/DiscoverMyself/inery-testnet-faucet-tasks" 14 | }, 15 | "homepage": "https://github.com/DiscoverMyself/inery-testnet-faucet-tasks", 16 | "dependencies": { 17 | "ineryjs": "github:inery-blockchain/ineryjs" 18 | } 19 | } -------------------------------------------------------------------------------- /aprameth/README.md: -------------------------------------------------------------------------------- 1 | ## Prerequisite 2 | 3 | ### Instal curl 4 | ``` 5 | sudo apt-get install curl 6 | ``` 7 | 8 | ### NodeJS & NPM 9 | - [Windows](https://nodejs.org/en/download/) Included NPM packages 10 | - Linux: 11 | ``` 12 | curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\ 13 | sudo apt-get install -y nodejs 14 | ``` 15 | 16 | 17 | 18 | ## How to run? 19 | 20 | **1. Change directory to `aprameth`** 21 | 22 | ```shell 23 | cd ./aprameth 24 | ``` 25 | 26 | 27 | **2. Install dependencies** 28 | 29 | ```shell 30 | npm install 31 | ``` 32 | 33 | **3. Create & edit `.env` file** 34 | ``` 35 | cp .env-sample .env 36 | ``` 37 | 38 | 39 | **4. Run the script** 40 | 41 | ``` 42 | npm run solution 43 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Inery testnet faucet tasks 2 | 3 | This is the base branch for tasks related to the Inery faucet. For each task that requires revision using GitHub, we will create a new branch named with the number of that task, such as 'task4', 'task5', etc. 4 | 5 | ## Getting Started 6 | 7 | To verify the quality of your code, you will need to clone the specific branch of the project and submit the required changes for that task. After making the necessary changes, you can create a pull request to submit your work for review. If the work is satisfactory, it will be approved. If there are any issues with the work, it may be labeled with specific comments indicating what needs to be improved or modified. It is important to carefully review and address any feedback provided in order to improve the quality of your work. 8 | -------------------------------------------------------------------------------- /aprameth/solution.mjs: -------------------------------------------------------------------------------- 1 | import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js' 2 | const url = process.env.NODE_URL 3 | 4 | const json_rpc = new JsonRpc(url) 5 | const private_key = process.env.PRIVATE_KEY; 6 | 7 | const account = process.env.INERY_ACCOUNT 8 | const actor = process.env.INERY_ACCOUNT 9 | const signature = new JsSignatureProvider([private_key]); 10 | 11 | const api = new Api({ 12 | rpc: json_rpc, 13 | signatureProvider: signature 14 | }) 15 | 16 | async function create(id, user, data){ 17 | try{ 18 | const tx = await api.transact({ 19 | actions:[ 20 | { 21 | account, 22 | name:"create", 23 | authorization:[ 24 | { 25 | actor, 26 | permission:"active" 27 | } 28 | ], 29 | data:{ 30 | id, user, data 31 | } 32 | } 33 | ] 34 | },{broadcast:true,sign:true}) 35 | 36 | 37 | console.log("=======================================================================") 38 | console.log("===================== CREATE transaction details ======================") 39 | console.log("=======================================================================") 40 | console.log(tx, "\n") 41 | console.log("Response from contract :", tx.processed.action_traces[0].console) 42 | console.log("\n") 43 | }catch(error){ 44 | console.log(error) 45 | } 46 | } 47 | 48 | async function read(id){ 49 | try{ 50 | const tx = await api.transact({ 51 | actions:[ 52 | { 53 | account, 54 | name:"read", 55 | authorization:[ 56 | { 57 | actor, 58 | permission:"active" 59 | } 60 | ], 61 | data:{ 62 | id 63 | } 64 | } 65 | ] 66 | },{broadcast:true,sign:true}) 67 | 68 | console.log("=======================================================================") 69 | console.log("===================== READ transaction details ========================") 70 | console.log("=======================================================================") 71 | console.log(tx, "\n") 72 | console.log("Response from contract :", tx.processed.action_traces[0].console) 73 | console.log("\n") 74 | }catch(error){ 75 | console.log(error) 76 | } 77 | } 78 | 79 | async function update(id, data){ 80 | try{ 81 | const tx = await api.transact({ 82 | actions:[ 83 | { 84 | account, 85 | name:"update", 86 | authorization:[ 87 | { 88 | actor, 89 | permission:"active" 90 | } 91 | ], 92 | data:{ 93 | id, data 94 | } 95 | } 96 | ] 97 | },{broadcast:true,sign:true}) 98 | 99 | 100 | console.log("=======================================================================") 101 | console.log("===================== UPDATE transaction details ======================") 102 | console.log("=======================================================================") 103 | console.log(tx, "\n") 104 | console.log("Response from contract :", tx.processed.action_traces[0].console) 105 | console.log("\n") 106 | }catch(error){ 107 | console.log(error) 108 | } 109 | } 110 | 111 | async function destroy(id){ 112 | try{ 113 | const tx = await api.transact({ 114 | actions:[ 115 | { 116 | account, 117 | name:"destroy", 118 | authorization:[ 119 | { 120 | actor, 121 | permission:"active" 122 | } 123 | ], 124 | data:{ 125 | id 126 | } 127 | } 128 | ] 129 | },{broadcast:true,sign:true}) 130 | 131 | 132 | console.log("=======================================================================") 133 | console.log("===================== DESTROY transaction details =====================") 134 | console.log("=======================================================================") 135 | console.log(tx, "\n") 136 | console.log("Response from contract :", tx.processed.action_traces[0].console) 137 | console.log("\n") 138 | }catch(error){ 139 | console.log(error) 140 | } 141 | } 142 | 143 | 144 | async function main(id, user, data){ 145 | await create(id, user, data) 146 | await read(id) 147 | await update(id, data) 148 | await destroy(id) 149 | } 150 | 151 | main(1, account, "CRUD Transaction via JSON RPC") --------------------------------------------------------------------------------