Local Development on testnet

Want to develop locally? We'll show you how to get started with near-shell

Requirements

IMPORTANT: Make sure you have the latest version of NEAR Shell and Node Version > 10.x

  • npm (Get it here)

  • node version 10.x(Get it here)

  • near-shell The NEAR cli tool.

    • Install withnpm i -g near-shell

    • Check out the commands here‚Äč

  • Whatever frontend build tools you prefer.

    • By default, gulp is used for compiling. Check it out here. (You shouldn't need to do any config for gulp specifically).

    • If you're interested in using React, we have an example template here.

1. Create a new project

near new_project [YOUR_PROJECT_DIR]

After this, cd into the project directory and run npm install

cd ./[YOUR_PROJECT_DIR] && npm install

2. Authorize NEAR Shell on your NEAR account

You'll now want to authorize NEAR shell on your NEAR account, which will allow NEAR Shell to deploy contracts on your NEAR account's behalf (and spend your NEAR account balance to do so).

If you don't have a NEAR account yet, take a look at how to create a NEAR account.

Type the command near login which should return a url:

Example Shell
Please navigate to this url and follow the instructions to log in:
https://wallet.nearprotocol.com/login/?title=NEAR+Shell&public_key={publicKey}

From there enter in your terminal the same account ID that you authorized:

Please enter the accountId that you logged in with: <asdfasdf>

3. Write the smart contract

Your project is pre-seeded with a "Hello World" contract which you can deploy right away, so feel free to head to step 4.

If you've already successfully deployed a contract, you'll probably want to start coding your own smart contract. If so, you'll find the below resources helpful.

For a deep dive into the file structure of a NEAR Project template, take a look here:

4. Create an account for your contract

Let's now deploy your contract to the same TestNet which the NEAR Studio IDE deploys to. Navigate to your source directory in command line, and create an account for your contract

near create_account <yourcontractname> --masterAccount=<login> --initialBalance <initalbalance>

--masterAccount= : specifies which account's key should be used to deploy the contract initialBalance : specifies how much to seed the contract balance with

You should see the success message:

Account <yourcontractname> for network "default" was created.

The last step is now to update the src/config.js to use <yourcontractname> for deploy.

src/config.js
(function() {
const CONTRACT_NAME = '<yourcontractname>'; /* TODO: fill this in! */
const DEFAULT_ENV = 'development';
...
})();

5. Deploy your contract and start the web server

Deploy your contract to TestNet and start web server for the frontend.

npm run start

You can run npm run start each time you want to redeploy the updated smart contract, or to restart your web server.

For help using cli tools, use near. To get a list of available npm scripts use npm run.

6. Test the smart contract

Within the application's directory run either:

Test on the TestNet:

NODE_ENV=development npm test

Test using locally running node: (Using TestNet is recommended for now)

npm test

That's it! The tests will run against the instance that you've deployed to TestNet!

The tests in src/test.js will run against the deployed contract.

7. Deploy contract to TestNet and frontend to GitHub pages

npm run deploy