Quick Start

Important

This page is intended to guide you through a quick setup to develop, test, and deploy your smart contract. We assume you have a general knowledge of blockchain, smart contract development, and TypeScript.

Tip

  • If you want to learn the concepts from the ground up and learn by doing, check out our Tutorial and reference the concepts listed in Docs when something is not clear.

  • If you want to learn with a real-world example, check out our Course which you can follow and see how things are tested. Also keep the Docs page handy for reference.

NEO•ONE makes coding, testing and deploying Neo dapps easy, fast, efficient and enjoyable.



Installations

  1. Install NodeJS >= 10.16.0 (Latest version recommended)

  2. Follow the installation instructions for Create React App to make a new project.

    • Be sure to invoke Create React App with the --template typescript in order to enable TypeScript support: npx create-react-app token --template typescript
  3. Install NEO•ONE using either yarn or npm

yarn add @neo-one/suite
npm install @neo-one/suite

Alternatively, install the individual packages @neo-one/suite wraps for you:

yarn add @neo-one/cli @neo-one/client @neo-one/smart-contract @neo-one/smart-contract-test @neo-one/smart-contract-lib @neo-one/smart-contract-typescript-plugin
npm install @neo-one/cli @neo-one/client @neo-one/smart-contract @neo-one/smart-contract-test @neo-one/smart-contract-lib @neo-one/smart-contract-typescript-plugin
  1. Run yarn neo-one init or npx neo-one init

The command above generates a sample HelloWorld.ts smart contract, a sample test for the contract HelloWorld.test.ts, a config file .neo-one.config.ts, and a neo-one folder with important modules.


A Contract in NEO•ONE

Every NEO•ONE smart contract starts with a TypeScript source file that exports a single class extending SmartContract.

import { SmartContract } from '@neo-one/smart-contract';

// Token is the contract name
export class Token extends SmartContract {
  public readonly mutableSupply: Fixed<8> = 0;

  //
  @constant
  public get totalSupply(): Fixed<8> {
    return this.mutable;
  }
}

Note

  • Types for smart contract development can be imported from @neo-one/smart-contract

  • Types for testing can be imported from @neo-one/client


A Test in NEO•ONE

Run the tests using yarn test OR npm test. It’s a convention to put smart contract tests under src/__tests__/, e.g. src/__tests__/Token.test.ts.

/**
 * @jest-environment node
 */
import { withContracts } from '../neo-one/test';

describe('Token', () => {
  test('exists', async () => {
    // "token" is the contract name
    await withContracts(async ({ token }) => {
      expect(token).toBeDefined();
    });
  });
});

Note

withContracts() is a generated helper that will expose all your contracts, their methods and properties along with other useful options. See Testing for more details.


Quick Commands

Build

yarn neo-one build

Run yarn neo-one build when you are done making changes to the contract(s). It not only builds the necessary code for the contract(s) but also updates the generated types and helpers. Specifically the command will:

  1. Start up a local private Neo network (if one has not already been started).
  2. Setup wallets for testing with various amounts of NEO and GAS.
  3. Compile the project’s smart contract(s).
  4. Deploy the smart contracts to the private Neo network.
  5. Generate code for use in your decentralized app.

Test

Run your tests with:

yarn test

or

npm test

Note

For more command line help and options, check out the CLI page.


Client Integration

Integrating the NEO•ONE client APIs in a vanilla JavaScript or TypeScript application is very simple - assuming we have a contract called Token and we’re in the src/index.ts file using the default NEO•ONE toolchain paths:

import { createClient, createTokenSmartContract } from './neo-one';

const client = createClient();
const token = createTokenSmartContract(client);
// "Token" is the name of this example smart contract
// for example:
// if your contract name is Test
// then the function will become createTestSmartContract()

Check out our Client APIs page for more details.


Deploy

Checklist before deploying to TestNet:

  1. Get a Neo wallet
  2. Get TestNet GAS in your wallet
  3. Create a migration file

You first need a wallet, the wallet’s private key and sufficient GAS to deploy.

Wallet set-up:

  1. Go to https://neotracker.io/
  2. Go to “Wallet” tab.
  3. Click on “New Wallet”.
  4. Enter a password (make sure you save this password), which is used to unlock the wallet later.
  5. Click on "Download Encrypted Key" (this will generate a .txt file that can be used to unlock your wallet via “Keystore File” option).
  6. Save the private key somewhere secure.
  7. Click Continue to view your wallet.
  8. (Optional) Generate a PDF of your wallet by clicking on “Print paper wallet”
  9. (Optional) Scroll down to “Details” when viewing your wallet to access the options of the previous steps (such as to view your private key or download a keystore file).

Migration File:

Create a migration.ts (migration.js if using JS) at the path specified in your NEO•ONE configuration file.

Tip

Visual Studio Code might display single child folders in "compact form" and prevent you from creating a new file under neo-one folder. Disable "compact folder" in "settings" if needed.

Example:

import { MigrationContracts } from '../src/neo-one';

export default ({ token, ico, escrow }: MigrationContracts, _network: string) => {
  token.deploy();
};

Note

For more details on deployment specifics and migration files, check out the Deployment page.

Get Test coins

You can get test coins automatically from https://neowish.ngd.network/

Limited to 1000 NEO and 1000 GAS per day.

If you need more than that. You must apply through Neo website. Please follow the instructions here: https://docs.neo.org/docs/en-us/network/testnet.html#applying-for-test-coin-from-neo-website

Note

Deploy to TestNet:

yarn neo-one deploy

Deploy to MainNet (or others):

yarn neo-one deploy --network <network>

Where network is one of the keys provided by your configuration (.neo-one.config.ts) under the networks property. By default neo-one deploy will use the test key.

Note

We HIGHLY recommend deploying to both a local private network and the Neo TestNet before attempting to deploy to the MainNet.

Explore with NEO Tracker

If your deployment to the TestNet was successful you should be able to find your contract at https://testnet.neotracker.io/browse/contract/1.

Edit this page
  • Quick Start
  • Getting Started
  • Environment Setup
  • CLI
  • Playground
  • Contract Mixins
Next Article
Getting Started
DOCS
InstallationMain ConceptsAdvanced GuidesAPI ReferenceContributing
CHANNELS
GitHubStack OverflowDiscord ChatTwitterYouTube
COPYRIGHT © 2021 NEO•ONE