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.
Install NodeJS >= 10.16.0 (Latest version recommended)
recommended
)recommended
)Follow the installation instructions for Create React App to make a new project.
--template typescript
in order to enable TypeScript support: npx create-react-app token --template typescript
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
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.
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
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.
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:
Run your tests with:
yarn test
or
npm test
Note
For more command line help and options, check out the CLI page.
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.
You first need a wallet, the wallet’s private key and sufficient GAS to deploy.
https://neotracker.io/
“Wallet”
tab.“New Wallet”
."Download Encrypted Key"
(this will generate a .txt
file that can be used to unlock your wallet via “Keystore File”
option).Continue
to view your wallet.“Print paper wallet”
“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).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.
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
- It costs about 500 GAS to deploy a simple contract. Checkout System Fees for more details.
- You should then be able to see the assets in your wallet at https://testnet.neotracker.io
yarn neo-one deploy
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.
If your deployment to the TestNet was successful you should be able to find your contract at https://testnet.neotracker.io/browse/contract/1.