Page cover

🍬Testing with Truffle

A step-by-step guide for creating a Truffle project and deploying it to your private StealthTest environment.

Before you begin, please make sure to create your StealthTest environment and have access to the RPC URL and chain ID.

This document is intended to act as a quick-start integration guide for new Truffle projects. If you already have an established Truffle project, skip to step 3.

For more information on Truffle, please access the documentation here: Truffle documentation

  1. Install Truffle

    1. npm install -g truffle

  2. Create a new Truffle project

    1. truffle unbox metacoin truffle-tutorial

    2. This is an example project that creates a new token called MetaCoin

    3. Important directories include

      1. contracts/: Directory for Solidity contracts

      2. migrations/: Directory for scriptable deployment files

      3. test/: Directory for test files for testing your application and contracts

      4. truffle-config.js: Truffle configuration file

      5. Output from creating your new Truffle project:

truffle unbox metacoin truffle-tutorial
Starting unbox...
βœ“ Preparing to download box βœ“ Downloading βœ“ Cleaning up temporary files βœ“ Setting up box
Unbox successful, sweet!
Commands:
Compile contracts: truffle compile
Migrate contracts: truffle migrate
Test contracts: truffle test
Your new Truffle project will have the above file structure
  1. Ensure your contracts are working properly by running the test suite

    1. truffle test

    2. Output from successful tests

  1. Compile your contracts

    1. truffle compile

  1. Configure your Truffle project

    1. npm i @truffle/hdwallet-provider

    2. Using your StealthTest URL, update truffle-config.js

      1. * will match any network ID

      2. Use any private key provided by StealthTest and remove the 0x prefix.

      3. Note: Each StealthTest environment comes with 5 pre-funded wallets, but please never use these on mainnet. You may also quickly fund your own wallet with our Faucet but please never share your private key with us or anyone you don't know.

    3. Example truffle-config.js below

  1. Deploy your contracts

    1. truffle migrate

    2. Contract addresses will be output in the console.

And that's it! You're now testing in private using StealthTest! πŸ’ͺ

Last updated

Was this helpful?