Contract
    Cargo.toml
    README.md
    build.bat
    build.sh
    src
        lib.rs
    test.sh
README.md
frontend
    .eslintrc.js
    README.md
    contract
        README.md
        build-contract.sh
        cleanup.sh
        dev-deploy.sh
    next-env.d.ts
    next.config.js
    package.json
    src
        pages
            api
                hello.js
        public
            error-notification.svg
            near-logo.svg
            search-icon.svg
            vercel.svg
        styles
            globals.css
    tsconfig.json
    windi.config.ts

# Blockchain Business Card v2

try it out here

https://block-cards.vercel.app/

This is NEAR chain dApp consisting a relatively simple smart contract written in rust and implemented with a Nextjs front end.

The contract allows you to _"mint"_ a business card for 5 NEAR.
Things you can do with you business card:

- Add a website.
- Display your NEAR account id.
- Claim blockchain development experience.
- Vouch and/or refute other business card holders personal claims.

All Business Cards will display their respective Net Vouches as a public rating.

__To get started with deploying the contract and starting up fronted check the README here in [/frontend/](frontend/README.md)__

Alternatively,

__To learn about the internals and the Rust smart contracts follow the README in [/Contract/](Contract/README.md)__

-----
## Screenshots

![site gif](https://i.imgur.com/kxvtUN5.gif)

----

__WARNING.__ - If you're on Windows please make sure you're using WSL2 (Windows Subsystem for Linux) and that your End of Line settings for files is set to `LF` and not `CRLF` on the, in particular for the  `.sh` script files, otherwise you might have trouble running the shell scripts.

_Note. I have yet to figure out the economics. But it would be interesting to budget the amount of times you can claim experience via time gating and ask the users to pay a small fee if they want to add additional experience within that time period. Or if a cards Net Vouches reaches 0, we could remove that experience from that card and the owner would have to pay to reclaim that experience._ 

---

I have yet to figure out the economics. This was built for the NEARxEncode Bootcamp Jan 2022.
## Todo:
    x add error catching inside of provider. 
    x add view functions to provider.
    - implement propper typings for callFunction's
    - better handling of error/loading states (maybe use a stack or queue to track)
    - add loading spinners per component vs page.
    - implement contract log indexing w/ graphql.
    
---

# This Frontend Was Created Using Nextjs

Before you run any scripts i encourage you to follow the [`README.md`](/frontend/contract/README.md) inside of the `/frontend/contract` directory.

or... TLDR. do the following:

_from within the `frontend/contract/` directory..._

1. run `./dev-deploy.sh`

2. run `near call $CONTRACT new --accountId $CONTRACT` with the proper `$CONTRACT` set.

3. Set the proper contract account name in the `frontend/.env` file.

4. run 'yarn install'

5. run 'yarn start'

------

_The following is auto-generated by create-react-app_

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
# Scripts Created With The [near-sdk-as Starter Kit](https://github.com/Learn-NEAR/starter--near-sdk-as)

These following scripts will guide you through building the rust smart contract and deploying it to testnet using the NEAR CLI.

__You must complete these steps for the frontend to work propperly__

If you would like to continue with the in-depth tour and are comming from the [/Contract/README.md](../../Contract/README.md) please continue to step 0.

## Step 0

(__OPTIONAL__)
Step 1 runs the follow commands via a script anyways.

This is just for insight as to whats going on for those interested. (aka future me)

Run the build-contract.sh command from the within this directory.

    ./build-contract.sh

This builds the webasembly file, `.wasm`, from within the `/Contract/` directory and copies it into the `frontend/contract/wasm32_out/` folder as `contract.wasm`

Check out the [script](../../Contract/build.sh) to see exactly what is does.

*Note. This webassembly in reality has nothing to do with the function of the front end directly. Meaning when your frontend is communicating with the smart contract it's never using these `.wasm` files directly. The files are instead used by the Near CLI to be able to deploy a Smart Contract onto an account on the blockchain. This account is what is executing your 'backend' logic*

## Step 1

Run the dev-deploy.sh script to build the contract and then execute the Near CLI commands that will deploy the contract onto a development account generated by the Near CLI itself. __Follow the script instructions careufully.__

    ./dev-deploy.sh

Once you have followed all the instructions and set your `$CONTRACT` enviroment variable from within your terminal correctly (check with `echo $CONTRACT`) run the following.

    near call $CONTRACT new --accountId $CONTRACT

This will call the `new()` method on the smart contract deployed onto the account created by the `dev-deploy.sh` script. 

_By passing in the same contract account name (ie `$CONTRACT`) as the `--acountId` argument, the contract invokes itself and is its own owner, saved onto the `owner_id` feild of the `Contract` main `struct`, seen here in [lib.rs](../../Contract/src/lib.rs). Check it out explore the contract internals._

# Step 2

Before You can build the frontend we have to set the correct `.env` variable for the account id the contract is deployed onto. You can see workspace varaible you set for the contract account id with `echo $CONTRACT`. There should also be new folder generated in this directory called `/neardev/` with the account id as well.

Make sure the correct contract account id is set on the `REACT_APP_CONTRACT_NAME` environment variable within [`frontend/.env`](../.env)

Also make sure that your terminal is in the `/frontend/` directory before running these next commands. Run.
  
    yarn install

and

    yarn start

Now you can play with App on the Browser!

# Clean up

To clean up the project run this command from within this directory.

_Note. Make sure you set an account as a beneficiary with `export $BENEFICIARY=myaccountexample.testnet`_

    ./cleaup.sh
    
This script will delete the development account created by `near dev-deploy` which was ran from within the script in __Step 1__ and transfer any NEAR currency in the account to the `$BENEFICIARY` account. (free testnet money!).

It will also delete `/contract/neardev` directory and its contents.

**Get more info at:**

* [NEAR CLI Docs](https://docs.near.org/docs/tools/near-cli)
# Created with Rust Smart Contract Template

## Getting started

If you would just like to play with the contract using Rust this is your place to start.
If you would like do deploy the contract to testnet and have it ready for the frontend  see [`/frontend/contract/`](../frontend/contract/README.md)

_MAKE SURE YOUR TERMINAL IS IN THE RIGHT DIRECTORY_.

0. __Exploring the contract:__

    This contract's code can be found inside of the [`lib.rs`](/src/lib.rs) file. In NEAR we usually compile our contracts as a library because it will be used by accounts as a library when managing the public methods and data stores for the contract as opposed to a binary file which is just like a one time exectuable.
    
    Once compiled with the correct flags (see __Building the contract__ below), you can browse the actual inside of the target folder `target/wasm32-unknown-unknown/release/<name>.wasm` if you are interested. _Note. This wasm is auto generated so it might not be very readable but its interesting regardless imo._

1. __Building the contract:__

    `RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release`

Test the contract 

    `cargo test -- --nocapture`

2. __Testing the contract:__

   This will run all the test while display macros like `pintln!()` in the contract code with the `--nocapture` option.

**Get more info at:**

* [Rust Smart Contract Quick Start](https://docs.near.org/docs/develop/contracts/rust/intro)
* [Rust SDK Book](https://www.near-sdk.io/)
