@libertypie/truffle-seeder

1.1.9 • Public • Published

Truffle Seeder (From Liberty Pie)

Easily seed initial data to smart contracts using this npm package

Installation

via npm

npm i --save @libertypie/truffle-seeder

via yarn

yarn add  @libertypie/truffle-seeder

Usage

Create new seed file

yarn seeder-init --contract HelloContract --method SetHelloMethod

the --contract is the contract you are targeting (eg. HelloContract)
and --method is the method or function in the targeted contract

after the seed files has been created, check the seeds folder in your project root and edit the file in the files sub folder

below is a sample of how a seed file looks like

module.exports = {
    contract: 'HelloContract',
    method:   'SetHelloMethod',
    data: [
        /* 
         * to seed args multiple times, add extra arrays
         ['arg1','arg2',...'argn'],
         ['arg1', 'arg2'...'argn']
        */
    ]
}

You add the args using an array inside the data array as shown

Seed File Options

contract:

The name of the contract you are targeting, it should exist in truffle build folder

method:

The method or function in the targetted contract where the data will be fed to

processor:

The processor is the function responsible for processing the data and calling the method/function from the contract The default processor is located at src/processors/StandardSeedProcessor.js

below is a seed file with a custom processor

module.exports = {
    contract: 'HelloContract',
    method:   'SetHelloMethod',
    processor: customDataProcessor,
    data: [
        /* 
         * to seed args multiple times, add extra arrays
         ['arg1','arg2',...'argn'],
         ['arg1', 'arg2'...'argn']
        */
    ]
}

// customDataProcessor
customDataProcessor = async ({
    contractName,
    contractInstance, 
    contractMethod, 
    argsArray,
    networkId,
    web3,
    web3Account
}) => {
  //process and insert data here 
}

Seeding the data

To seed the data to the contract's method, you will run the command below

 yarn seeder-run 

About

The npm package is developed maintained by the team at LibertyPie Project

Contribution

To contribute, kindly fork the project, at project root create a dev.env file, insert APP_ROOT_DIR pointint to your truffle project where testing will be done, example:

 APP_ROOT_DIR=/path/to/truffle/solidity/project

Package Sidebar

Install

npm i @libertypie/truffle-seeder

Weekly Downloads

0

Version

1.1.9

License

MIT

Unpacked Size

24.8 kB

Total Files

10

Last publish

Collaborators

  • zak.r