# Polkadot

## Foundation

Some Foundation References:

* Polkadot Whitepaper: <https://polkadot.network/PolkaDotPaper.pdf>

Testnet: Kusama, Rokoko, westend

Unit:

* Dot
* Plancks : 1 dot = 10 Billions Plancks. Plancks is the equivalent to Satoshi

Contact:

* Bill Laboon: Web3 Foundation
  * <bill@web3.foundation>

Development environment:

* Ink programming language for Polkadot: ink! is an [eDSL](https://wiki.haskell.org/Embedded_domain_specific_language) to write WebAssembly based smart contracts using the Rust programming language. The compilation target are blockchains built on the [Substrate](https://github.com/paritytech/substrate) framework: <https://github.com/paritytech/ink#how-it-works>
* Edgeware: <https://contracts.edgewa.re/#/> -> start your First SC on that env

## First SmartContract on Edgeware

To build a first SC, info you must know, so foundations:&#x20;

* <https://wiki.polkadot.network/docs/en/build-build-with-polkadot#so-you-want-to-build-a-smart-contract>
* <https://contracts.edgewa.re/#/> -> for developping your first SC on Wasm locally

```
// 1. SETUP:
// Install Rust Env
$ curl https://sh.rustup.rs -sSf | sh -s -- -y

// Update Rust version
$ rustup target add wasm32-unknown-unknown --toolchain stable
 rustup component add rust-src --toolchain nightly
 rustup toolchain install nightly-2020-06-01
 rustup target add wasm32-unknown-unknown --toolchain nightly-2020-06-01

// Install nightly:
$ sudo rustup toolchain install nightly
$ rustup component add --toolchain nightly rust-src

// 2. Create a Ink project:
//  ink! command line utility which will make setting up Substrate smart contract projects easier.
// You can install the utility using Cargo with:
$ cargo install --git https://github.com/hicommonwealth/cargo-contract cargo-contract --force

// Check if the ink! utility is well installed (so the Cargo-contract module)
$ cargo contract --help

// Create the SC project with Cargo and the module contract
$ cargo contract new flipper

// Testing the code using using the off-chain test environment that ink! provides
$ sudo cargo +nightly test

//3. Compile the SmartContract
$ cargo +nightly contract build
// if error message, https://github.com/rust-lang/rustup/issues/2601

// Create ABI: By running the next command we'll generate the contract metadata (a.k.a. the contract ABI):
$ cargo +nightly contract generate-metadata

//4. Running a Substrate Node (Edgeward Local node)

// Install Docker first: https://docs.docker.com/get-docker/
// For Apple M1 machine: https://docs.docker.com/docker-for-mac/apple-m1/

// Clone Gith code of Edgeware node:
$ git clone https://github.com/hicommonwealth/edgeware-node
$ cd edgeware-node/docker
$ docker-compose up // !! issue crash when starting dump, see option here under

// Then install manually the Edgeward node: https://github.com/hicommonwealth/edgeware-node/tree/v3.2.0
// You need to have the protobuf compiler: https://grpc.io/docs/protoc-installation/
// On Mac, you need to have brew package manager installed, on big sure there are issue : https://github.com/Homebrew/discussions/discussions/501
$ brew doctor
$ git -C $(brew --repo homebrew/core) checkout master
$ brew doctor

//Install protobuf compiler
$ brew install protobuf
$ protoc --version

// Go on the folder where you clone the edgeware-node
$ ./setup.sh
// Issue with the librocksdb-sys not yet supported on MAC Intel Chip https://github.com/substrate-developer-hub/substrate-node-template/issues/139
// Fix it: https://github.com/substrate-developer-hub/substrate-node-template/issues/139

// GOOD: TO Fix the issue of Librocksdb not yet coded to support M1 chip:
// First follow https://zhuanlan.zhihu.com/p/337224781, open it on Chrome and Select English to translate
// Select the Nighly Rust version for last feature:
$ RUSTUP_UPDATE_ROOT=https://dev-static.rust-lang.org/rustup sh <(curl --proto '=https' --tlsv1.2 -sSf https://dev-static.rust-lang.org/rustup/rustup-init.sh) --default-toolchain nightly

// Then for the last issue, a code update of trphandlers.rs is needed: https://github.com/substrate-developer-hub/substrate-node-template/issues/139
// Edit the file located on /Users/lemaimn/.cargo/registry/src/github.com-1ecc6299db9ec823/wasmtime-runtime-0.19.0/src/traphandlers.rs
// line 169 replace with (*cx.uc_mcontext).__ss.__pc as *const u8
// Then Recompile and it will succeed without error:
$ sudo make build

// Then launch the node:
$ ./target/release/node-template --dev --tmp
// You can browse your Polkadot Node with https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer and select local ledger

// To launch Edgeware:
$ ./edgeware --dev --tmp
// You can use also same Polkadot UI:https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A63249#/contracts
// You need to use Chrome (for security issue redirect,)
```

## Equivalent of Metamask Pluggin on Chrome

You can use: <https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd>

## Polkadot UI

You can go on  -> <https://github.com/polkadot-js/apps>

## Deploy SC on Beresheet Chain

* <https://beresheet-faucet.vercel.app> Faucet
