LorranSutter / Signed-transactions-demo

Server side application to perform smart contract transactions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Signed Transactions Demo

Server side signed transactions for Smart Contracts using Solidity, Truffle and Node.js presented as lab assingment for BCDV1011 - Design Patterns for Blockchain from Blockchain Development program from George Brown College.

🏃 How to run

Open your terminal in the folder you want to clone the project

# Clone this repo
git clone https://github.com/LorranSutter/Signed-transactions-demo.git

# Go to the project folder
cd Signed-transactions-demo

# Install dependencies
npm install

Now you will need two opened terminals to run the project. One for truffle to simulate the EVM and another one for the server.

Truffle will run on http://127.0.0.1:9545/

Frontend will run on http://localhost:5000/

## In the first terminal ##

# Go to smart contract folder
cd src/SmartContract

# Init truffle
truffle develop

After the last command, the RPC URI and a list of account addresses and private keys will be shown in the terminal, you will need one of these (address, PK) pairs to execute transactions. Choose, copy and paste one of these pairs and the RPC URI as the following instructions below.

To run the application you are will need to set your own configurations of port, RPC uri, account address and private key. Create the following .env file in the indicated path and format with your customized configurations:

// ./.env

PORT=5000
RPC_URI="http://127.0.0.1:9545/"
ACCOUNT_ADDRESS="0x9103cd7582bee22423648dfe02e4cfcc455e7ead"
PRIVATE_KEY="22c643e9b3efdf8a055094210e570116b98e619fe92ce5c825810571b3f76707"

Now you may execute the following command:

# Run migrations
migrate

The previous command will generate a new ABI and write contract address in a JSON file. You do not have to worry about importing these info in the backend though. Also you may change the smart contract and run migrations again to see your changes.

## In the another terminal ##

# Go to backend application
cd ..

# Run the project
npm run start

# Or to use nodemon
npm run dev

📖 References and technologies 💻

  • Solidity - smart contract programming language
  • Truffle - dApp environment
  • Ethereumjs-tx - perform smart contract transactions in server side
  • Web3.js - interact with smart contracts
  • Dotenv - loads environment variables from a .env file
  • Express.js - web application framework
  • Pug - template engine for Node.js and for the browser

About

Server side application to perform smart contract transactions

License:MIT License


Languages

Language:JavaScript 75.4%Language:CSS 12.5%Language:Solidity 6.2%Language:Pug 5.8%