Quick Start

OpenZeppelin Starter Kits come with everything you need to start using upgradeable Smart contracts inside your applications. It also includes all the configuration required to deploy to different networks.

Installation

Ensure you are in a new and empty directory, and run the unpack command with the name of the starter kit you want to use, e.g., starter.

openzeppelin unpack <kit_name>

You can use other starter kits as well. You can find them all here.

Run

In a new terminal window, run your local blockchain:

ganache-cli --deterministic

In your original terminal window, at the top level of your folder, initialize the project and follow the prompts:

openzeppelin init

In a new terminal window, in the client directory, run the React app:

cd client npm run start

Open a web browser and navigate to: http://localhost:3000.

You can now start building your dapp!

Contracts

When developing, Solidity contracts should be placed in the top level of the Starter Kit in the contracts folder.

Using the SDK

Compile

compile

To compile your contracts, use:

openzeppelin compile

This will compile your contracts and create build artifacts which are then stored in a newly created build directory.

Create

create

To create an instance of your contract on the blockchain:

openzeppelin create

The cli will guide you through the process of creation, including offering you the ability to call a function at the time of deployment.

For ease of use, it is not necessary to compile your contracts prior to using create to deploy them. All contracts will be automatically compiled as a part of the create flow.

These instances are upgradeable but will always keep the same address. You can create as many instances of the same contract as you would like.

To learn more about upgradeable smart contracts: OpenZeppelin SDK

Interact

To simplify interacting with your contracts and blockchain, as well as handling small tasks such as sending ETH between addresses, OpenZeppelin-cli offers a number of convenient interactive commands that can be used directly from the command line.

call

To call a public method, use the following from the top level of your project command line:

openzeppelin call

Follow the command line prompt where you will be asked to choose your network, the address of the created contract instance, and the public method you would like to call.

send-tx

To send a transaction to a contract instance:

openzeppelin send-tx

Follow the command line prompt where you will be asked to choose your network, the address of the created contract instance, and a list of the public functions available to call. If you have any arguments to pass, the cli will prompt you to enter those before sending the transaction.

This is very useful for quickly testing a contract to see if a function does what you expect.

transfer

To quickly transfer funds on the network of your choice, the transfer command is available. Using transfer requires that your networks.js file is configured and that your node (such as ganache) has an unlocked address and you are able to send ETH (and have ETH to send).

openzeppelin transfer

This will guide you through several prompts and allow you to effortlessly transfer ETH directly from the command line.

balance

To query the ETH balance of the specified account:

openzeppelin balance [address]

Type openzeppelin to see a complete list of available commands directly from the command line or visit OpenZeppelin CLI for a complete api reference.

Test

Truffle can run tests written in Solidity or JavaScript against your smart contracts. Note the command varies slightly if you’re inside or outside of the truffle development console.

From inside the development console:

test

From outside the development console:

truffle test

Jest is included for testing React components. Compile your contracts before running Jest, or you may receive some file not found errors.

From inside the client directory when running this: npm run test

Build

To build the application for production, use the build script. A production build will be in the client/build folder.

npm run build