Code Monkey home page Code Monkey logo

mining's Introduction

Data Highway Inter-Chain Bridged Token Asset Mining

Table of Contents

Credits

Setup

Clone the repo

git clone https://github.com/DataHighway-com/mining
cd ./mining

Install Dependencies

Switch to relevant Node.js version using NVM and install dependencies

nvm use v11.6.0

Note: Otherwise may get error like no matching constructor for initialization of 'v8::String::Utf8Value'

npm install

Install Truffle and Test Framework with Ganache CLI (previously Ethereum TestRPC)

npm install -g truffle ganache-cli

Latest beta (see https://github.com/trufflesuite/ganache-cli/releases)

npm uninstall ganache-cli -g
npm install ganache-cli@beta -g

Configure Blockchain

Run Ethereum Client (in separate Terminal tab)

Delete DB folder if starting fresh

rm -rf ./db

Create DB folder

mkdir db && mkdir db/chain_database

Start Ethereum Blockchain Protocol Node Simulation that will be served on http://localhost:8545

Note:

  • 0xce31EeD26ff009f1F5e38408571ea174c5d54f20 is Ethereum address of seed 0x209c205f333b5a65cc428589a51bd9f2621e2fc01de1b02dbf8c0f0b68e4974e
  • 0xe66628e37eFE36098c148d2a3B970074999E95C6 is Ethereum address of seed 0x0edb559026c8f779be17b4c9d8e4dfc14bead6592241de4d6612f77769327f7f
  • These keys are defined in ./helpers/constants.js
ganache-cli \
	--account="0x209c205f333b5a65cc428589a51bd9f2621e2fc01de1b02dbf8c0f0b68e4974e, 50471238800000000000" \
	--account="0x0edb559026c8f779be17b4c9d8e4dfc14bead6592241de4d6612f77769327f7f, 100471238800000000000" \
	--unlock "0x209c205f333b5a65cc428589a51bd9f2621e2fc01de1b02dbf8c0f0b68e4974e" \
	--unlock "0x0edb559026c8f779be17b4c9d8e4dfc14bead6592241de4d6612f77769327f7f" \
	--port 8545 \
	--hostname localhost \
	--seed '0x209c205f333b5a65cc428589a51bd9f2621e2fc01de1b02dbf8c0f0b68e4974e' \
	--debug true \
	--mem true \
	--mnemonic 'end sleep vote expire arctic magic crack wrap toddler lizard acoustic owner' \
	--db './db/chain_database' \
	--verbose \
	--networkId=3 \
	--gasLimit=7984452 \
	--gasPrice=20000000000;

Compile and Migrate Contracts onto Network of choice (i.e. "development") defined in truffle.js

Compile
  • Compile Contract Latest - truffle compile (only changes since last compile)
  • Compile Contract Full - truffle compile --compile-all (full compile)
Migrate
  • Run Migrations Latest - truffle migrate
  • Run Migrations Full (Ropsten) - truffle migrate --reset --network ropsten
  • Run Migrations Full (Development) - truffle migrate --reset --network development
  • Run Contracts from specific Migration - truffle migrate -f <number>
  • Run Migration on specific network called 'live' defined in truffle.js - truffle migrate --network live

Note: If you get error Could not find suitable configuration file. then you're running the command in the wrong directory. Note: If the above results in a time-out, then instead run the following to try and uncover any other errors:

truffle develop
truffle(develop)> migrate --reset

References:

Build DApp Front-end

Build Artifacts (requires Default or Custom Builder such as Webpack to be configured)

npm run build

(same as truffle build)

Run DApp Node.js Server & Interact

Terminal 3 - Install & Run MongoDB

macOS

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

brew tap mongodb/brew
brew install [email protected]
brew services start [email protected]

Terminal 1 - Run Server

Drop DB. Build App and Run Dev Server:

npm run drop; npm run dev

Open open http://localhost:8080 in browser

Terminal 2 - Interact using cURL

  • Send request to server and receive response for authentication and authorisation to access specific API endpoints.
    • Register. JWT provided in response (i.e. {"token":"xyz"})
       curl -v POST http://localhost:7000/users/auth/register -d "network=ethereum-testnet-local&publicAddress=0x123&[email protected]&password=123456&name=Luke" -H "Content-Type: application/x-www-form-urlencoded"
       curl -v POST http://localhost:7000/users/auth/register -d '{"network": "ethereum-testnet-local", "publicAddress": "0x123", "email":"[email protected]", "password":"123456", "name":"Luke"}' -H "Content-Type: application/json"
      
    • Fetch the Nonce if it exists for given Public Address. Nonce provided in response (i.e. {"nonce":"123"})
       curl -v GET http://localhost:7000/users/show?network='ethereum-testnet-local&publicAddress=0x123'
      
    • Sign in using signature verification. JWT provided in response (i.e. {"token":"xyz"})
       curl -v POST http://localhost:7000/users/auth/login -d "network='ethereum-testnet-local'&publicAddress=0x123&signature=0x456&[email protected]&password=123456" -H "Content-Type: application/x-www-form-urlencoded"
       curl -v POST http://localhost:7000/users/auth/login -d '{"network": "ethereum-testnet-local", "publicAddress": "0x123", "signature": "0x456", "email":"[email protected]", "password":"123456"}' -H "Content-Type: application/json"
      
    • Access a restricted endpoint by providing JWT
       curl -v GET http://localhost:7000/users/list -H "Content-Type: application/json" -H "Authorization: Bearer <INSERT_TOKEN>"
      
    • Create user by providing JWT
       curl -v POST http://localhost:7000/users/create --data '[{"network": "ethereum-testnet-local", "publicAddress": "0x123", "signature": "0x456", "email":"[email protected]", "name":"Test"}]' -H "Content-Type: application/json" -H "Authorization: JWT <INSERT_TOKEN>"
       curl -v POST http://localhost:7000/users/create -d "network='ethereum-testnet-local'&publicAddress=0x123&signature=0x456&[email protected]&name=Test2" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: JWT <INSERT_TOKEN>"
      

Example 2:

  • Within the DApp transfer say 10 wei to Account No. 0x0000000000000000000000000000000000000000000000000000000000000001 that we created on Ethereum TestRPC

  • Check Account Balances from Terminal by loading External JavaScript file:

truffle exec './scripts/checkAllBalances.js’

Example 2:

$ truffle develop
truffle(develop)> compile
truffle(develop)> migrate
truffle(develop)> exec ./scripts/deployMxc.js

OR truffle exec ./scripts/deployMxc.js --network development

Watch

Watch for changes to contracts, app and config files. Rebuild app upon changes.

truffle watch

Reference

Test

truffle test
truffle test ./path/to/test/file.js

OR

$ truffle develop
truffle(develop)> test

Linter

Run Linter:

npm run lint

Truffle Interactive Console (REPL)

Run REPL on specified network and log communication between Truffle and the RPC

truffle console --network development --verbose-rpc

Try the following commands

web3

// Show existing MXCToken accounts
web3.eth.accounts

i.e. 
	[ '0xce31EeD26ff009f1F5e38408571ea174c5d54f20',
		'0xe66628e37eFE36098c148d2a3B970074999E95C6' ]

web3.eth.blockNumber

Remix

Refer to Remix

References

FAQ

  • Question: Why do I get the following error when running truffle test: Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!?
    • Answer: Running Ganache CLI with --blockTime 3 mines 1 block every 3 seconds, whereas if the blockTime option is omitted then blocks are mined instantly.
  • Question: Why do I get the following error when running truffle test: sender doesn't have enough funds to send tx. The upfront cost is: 1134439500000000000 and the sender's account only has: 320739879999999999?
    • Answer: When running Ganache CLI, provide more ETH to the default accounts (i.e. --account="0x0000000000000000000000000000000000000000000000000000000000000001, 50471238800000000000" \ provides 50 ETH to that account.) or restart the Ganache CLI

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.