This project is for the blockchain application My Dapp. It contains code for the Smart Contract, web-based dapp and NodeJS server.
In order to develop and build "My Dapp," the following pre-requisites must be installed:
- Visual Studio Code (or any IDE for editing Javascript)
- NodeJS
- Yarn (DappStarter uses Yarn Workspaces) ///(language:solidity ///) ///(blockchain:flow
- Flow CLI (https://docs.onflow.org/flow-cli/install) (after installation run
flow cadence install-vscode-extension
to enable code highlighting for Cadence source files) ///) ///(blockchain:solana - Solana CLI Tools
- Rust (see "Dependency Guides" at the end for help installing)
$ node --version
$ npm --version
$ rustup --version
$ rustc --version
$ cargo --version
$ solana --version
///)
Before you proceed with installation, it's important to note that many blockchain libraries either don't work or generate errors on Windows. If you try installation and can't get the startup scripts to completion, this may be the problem. In that case, it's best to install and run DappStarter using Windows Subsystem for Linux (WSL). Here's a guide to help you install WSL.
Blockchains known to require WSL: Solana
Using a terminal (or command prompt), change to the folder containing the project files and type: yarn
This will fetch all required dependencies. The process will take 1-3 minutes and while it is in progress you can move on to the next step.
You might see failures related to the node-gyp
package when Yarn installs dependencies.
These failures occur because the node-gyp package requires certain additional build tools
to be installed on your computer. Follow the instructions for adding build tools and then try running yarn
again.
///(blockchain:polygon
Before you can work with Matic's testnet, you need to request some tokens in your test accounts. To make this request type: yarn faucet
This will request tokens for all 10 test accounts. You may have to run this command a few times to see the token balances get updated. It isn't necessary to wait until all accounts have tokens – the account labeled (0) is the account used to deploy contracts. Once you see a balance for this account, you can continue.
///)
Using a terminal (or command prompt), change to the folder containing the project files and type: yarn start
This will run all the dev scripts in each project package.json.
///(blockchain:solana
The first time you run yarn start
there are a fair number of Rust libraries that are
downloaded and pre-compiled. As a result, it may be take from 5-10 mins. before the
dapp is compiled and launched the first time. On subsequent compilations, the build
time will only be a few seconds.
Here are the locations of some important files:
- Program Code: packages/dapplib/programs/src/lib.rs
- Dapp Library: packages/dapplib/src/dapp-lib.js
- Solana Wrapper: packages/dapplib/src/solana.js
- Blockchain Interactions: packages/dapplib/src/blockchain.js
- Data Layouts: packages/dapplib/src/scripts/layouts.js
- Deploy Script: packages/dapplib/src/scripts/deploy.js ///)
///(language:solidity
Here are the locations of some important files:
- Contract Code: packages/dapplib/contracts
- Dapp Library: packages/dapplib/src/dapp-lib.js
- Blockchain Interactions: packages/dapplib/src/blockchain.js
- Unit Tests: packages/dapplib/tests
- UI Test Harnesses: packages/client/src/dapp/harness
///)
///(language:cadence
Here are the locations of some important files:
- Contract Code: packages/dapplib/contracts
- Dapp Library: packages/dapplib/src/dapp-lib.js
- Blockchain Interactions: packages/dapplib/src/blockchain.js
- Unit Tests: packages/dapplib/tests
- UI Test Harnesses: packages/client/src/dapp/harness
///) To view your dapp, open your browser to http://localhost:5000 for the DappStarter Workspace.
We
///(language:solidity
yarn migrate
to compile contracts/*.sol files, deploy them to the blockchain.
Run the dapp in a separate terminal. You must have run npm run deploy
for the dapp to see most recent smart contract changes.
yarn dapp
runs the dapp on http://localhost:5001 using webpack dev server
Run the server in a separate terminal. You must have run npm run deploy
for the dapp to see most recent smart contract changes.
yarn server
runs NodeJS server app on port 5002 with NestJS
test-config.js
contains settings used by test scripts
Run tests using yarn test --script=[test file]
DappStarter currently does not provide blockchain migration scripts to be used in production. However, here are the scripts for generating production builds:
yarn build:prod
generates dapp bundle for production.
///)
///(language:rust
This section contains installation guides for common dev environments.
(Source: Solana) We suggest that you install Rust using the 'rustup' tool. Rustup will install the latest version of Rust, Cargo, and the other binaries.
Follow the instructions at Installing Rust.
For Mac users, Homebrew is also an option. The Mac Homebrew command is brew install rustup
and then
rustup-init
. See Mac Setup &
Installing Rust for more details.
After installation, you should have rustc
, cargo
, & rustup
. You should
also have ~/.cargo/bin
in your PATH environment variable.
///)