near / boilerplate-template-ipfs

A github template repository of an end-to-end application that demonstrates minimal UI to upload files using the IPFS protocol and download files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boilerplate Template React

Report a Bug · Request a Feature . Ask a Question

Pull Requests welcome code with love by near

Table of Contents

About

This project is created for easy-to-start as a React + IPFS skeleton template in the Pagoda Gallery. It was initialized with create-near-app. Clone it and start to build your own gallery project!

Built With

create-near-app, amazing-github-template

Getting Started

Prerequisites

Make sure you have a current version of Node.js installed – we are targeting versions 18+.

Read about other prerequisites in our docs.

Installation

Install all dependencies:

npm install

Install IPFS:

npm install -g ipfs

Initialize IPFS daemon:

jsipfs init

Allow our clients to talk to our jsipfs instance:

jsipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://localhost:5002", "http://localhost:3000", "https://webui.ipfs.io"]'
jsipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'

Build your contract:

npm run build

Deploy your contract to TestNet with a temporary dev account:

npm run deploy

Usage

Test your contract (must use node v16):

npm test

Start your IPFS daemon:

jsipfs daemon

Run your frontend in development mode:

npm run dev

Start your frontend in production mode:

npm start

Exploring The Code

  1. The smart-contract code lives in the /contract folder. See the README there for more info. In blockchain apps the smart contract is the "backend" of your app.
  2. The frontend code lives in the /frontend folder. /frontend/pages/index.tsx is a great place to start exploring. Note that it uses /frontend/contracts/ipfs-contract.ts, this is your entrypoint to learn how the frontend connects to the NEAR blockchain.

Deploy

Every smart contract in NEAR has its own associated account. When you run npm run deploy, your smart contract gets deployed to the live NEAR TestNet with a temporary dev account. When you're ready to make it permanent, here's how:

Step 0: Install near-cli (optional)

near-cli is a command line interface (CLI) for interacting with the NEAR blockchain. It was installed to the local node_modules folder when you ran npm install, but for best ergonomics you may want to install it globally:

npm install --global near-cli

Or, if you'd rather use the locally-installed version, you can prefix all near commands with npx

Ensure that it's installed with near --version (or npx near --version)

Step 1: Create an account for the contract

Each account on NEAR can have at most one contract deployed to it. If you've already created an account such as your-name.testnet, you can deploy your contract to near-blank-project.your-name.testnet. Assuming you've already created an account on NEAR Wallet, here's how to create near-blank-project.your-name.testnet:

  1. Authorize NEAR CLI, following the commands it gives you:

    near login

  2. Create a subaccount (replace YOUR-NAME below with your actual account name):

    near create-account near-blank-project.YOUR-NAME.testnet --masterAccount YOUR-NAME.testnet

Step 2: deploy the contract

Use the CLI to deploy the contract to TestNet with your account ID. Replace PATH_TO_WASM_FILE with the wasm that was generated in contract build directory.

near deploy --accountId near-blank-project.YOUR-NAME.testnet --wasmFile PATH_TO_WASM_FILE

Step 3: set contract name in your frontend code

Modify NEXT_PUBLIC_CONTRACT_NAME in frontend/.env.local that sets the account name of the contract. Set it to the account id you used above.

NEXT_PUBLIC_CONTRACT_NAME=near-blank-project.YOUR-NAME.testnet

Troubleshooting

On Windows, if you're seeing an error containing EPERM it may be related to spaces in your path. Please see this issue for more details.

Roadmap

See the open issues for a list of proposed features (and known issues).

Support

Reach out to the maintainer:

Project assistance

If you want to say thank you or/and support active development of Boilerplate Template React:

  • Add a GitHub Star to the project.
  • Tweet about the Boilerplate Template React.
  • Write interesting articles about the project on Dev.to, Medium or your personal blog.

Together, we can make Boilerplate Template React better!

Contributing

First off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated.

Please read our contribution guidelines, and thank you for being involved!

Authors & contributors

The original setup of this repository is by Jonathan Lewis.

For a full list of all authors and contributors, see the contributors page.

Security

Boilerplate Template React follows good practices of security, but 100% security cannot be assured. Boilerplate Template React is provided "as is" without any warranty. Use at your own risk.

For more information and to report security issues, please refer to our security documentation.

About

A github template repository of an end-to-end application that demonstrates minimal UI to upload files using the IPFS protocol and download files


Languages

Language:TypeScript 87.9%Language:CSS 6.7%Language:Shell 3.4%Language:JavaScript 2.0%