0.1.1 • Published 7 months ago

solidity-boilerplate-creator v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

solidity-boilerplate-creator

This tool provides a straightforward way to generate Solidity boilerplates for contracts, scripts, and tests.

Note: I'm a newcomer to Solidity development and have chosen Foundry for my toolchain, inspired by Patrick Collins' Blockchain Developer, Solidity, Foundry Full Course 2023.
This tool is tailored towards that setup and the folder structure recommended in the course.
The boilerplate templates can be modified to your needs, but other than that if you're not using Foundry, this tool might not fit your workflow.

Install

Since this is a CLI tool, I'd suggest that you install the package globally:

npm i -g solidity-boilerplate-creator

Usage

From the root folder containing the src, script, and test directories, run:

sol-create [options] <fileName>

OptionDescription
no optionCreate a contract boilerplate in the "src" folder
-s, --scriptCreate a script boilerplate in the "script" folder
-t, --testCreate a test boilerplate in the "test" folder
-V, --versionShow package version
-h, --helpDisplay help for command

Modifying Templates

If you wish to modify the default boilerplate templates, you can do so by editing the template files located in the templates directory. There are separate templates for contracts, scripts, and tests:

  • header_template.sol: Contains the common header used across all boilerplate types.
  • contract_template.sol: Specific content for contract boilerplates.
  • script_template.sol: Specific content for script boilerplates.
  • test_template.sol: Specific content for test boilerplates.

By modifying these files, you can customize the content of the boilerplates generated by the tool.

Using Placeholders

Placeholders allow for dynamic content insertion into the templates. They are defined in the config.json file and can be used in any template file. For example:

{
  "placeholders": {
    "LICENSE": "MIT",
    "COMPILER_VERSION": "0.8.18",
    "dummy_testing": "Replaced text"
  }
}

Then, in the template files, you can refer to these placeholders by wrapping the keys from the config.json file in double curly braces.

Here's a boilerplate template example:

// SPDX-License-Identifier: {{LICENSE}}

pragma solidity ^{{COMPILER_VERSION}};

//{{dummy_testing}}

And here's the final output:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

//Replaced text

You can define and use as many custom placeholders as you need in the config.json file.

Changelog

v0.1.1

  • Clarified the error messages.

v0.1.0

  • Initial release.
  • Basic functionality is in place for creating contracts, scripts, and tests boilerplates.
0.1.1

7 months ago

0.1.0

7 months ago