# solidity-structure

> Structure of ethereum contract in solidity language

Latest version **0.1.18** (published 2017-10-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install solidity-structure
pnpm add solidity-structure
yarn add solidity-structure
bun add solidity-structure
```

Provides the command `solidity-structure`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.18 |
| Published | 2017-10-05 |
| First published | 2017-01-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Vitiko |
| Maintainers | vitiko |

## Links

- npm: https://www.npmjs.com/package/solidity-structure
- Repository: https://github.com/vitiko/solidity-structure
- Homepage: https://github.com/vitiko/solidity-structure#readme
- Issues: https://github.com/vitiko/solidity-structure/issues
- npm.io page: https://npm.io/package/solidity-structure

## Dependencies (2)

- [yargs](https://npm.io/package/yargs.md) ^6.6.0
- [solidity-parser](https://npm.io/package/solidity-parser.md) ^0.4.0

## Recent versions

- 0.1.18 (latest) — 2017-10-05
- 0.1.17 — 2017-08-04
- 0.1.16 — 2017-08-04
- 0.1.15 — 2017-08-04
- 0.1.14 — 2017-04-28
- 0.1.13 — 2017-04-27
- 0.1.12 — 2017-04-27
- 0.1.10 — 2017-03-27
- 0.1.9 — 2017-03-23
- 0.1.8 — 2017-03-21
- 0.1.7 — 2017-03-13
- 0.1.6 — 2017-02-21
- 0.1.5 — 2017-02-17
- 0.1.4 — 2017-02-17
- 0.1.3 — 2017-02-16
- … 3 more at https://npm.io/package/solidity-structure/versions

## README

# Solidity structure 

Parse structure of ethereum solidity contract, including enums,constructor, structs. Based on [Solidity Parser library](https://github.com/ConsenSys/solidity-parser) from [ConsenSys](https://github.com/ConsenSys).

The goal of it is to take Solidity code as input and return an object as output that can be used to describe _all_ parts of Solidity smart contract.

[![Build status](https://img.shields.io/travis/vitiko/solidity-structure/master.svg?style=flat-square)](https://travis-ci.org/vitiko/solidity-structure)
[![Coverage](https://img.shields.io/codecov/c/github/vitiko/solidity-structure.svg?style=flat-square)](https://codecov.io/github/vitiko/solidity-structure?branch=master)
[![bitHound Code](https://www.bithound.io/github/vitiko/solidity-structure/badges/code.svg)](https://www.bithound.io/github/vitiko/solidity-structure)



## Instalation

`npm install solidity-structure`


## Usage in code


```javascript
const SolidityStructure = require("solidity-structure");

// Parse Solidity code as a string:
let result = SolidityStructure.parse("contract { ... }");

// Or, parse a file:
let result = SolidityStructure.parseFile("./path/to/file.sol");
```

## Usage in command line

(suppose `solidity-structure` package installed globally )
 
`user@host:/`solidity-structure MyContract.sol > contract-structure.json  

## Examples


### Contract constructor structure


Solidity contract [HasConstructor](test/fixture/WithConstructor.sol)

```javascript
pragma solidity ^0.4.4;

/**
* Contract with constructor
*/
contract WithConstructor {

  /**
   * My constructor long long description
   * @dev my constructor short description
   * @param uintParam Description of item 1
   * @param uintParam2
   */
   function  WithConstructor (  uint uintParam,  string stringParam,  uint uintParam2) {
     //empty
   }
}
```


Structure of [constructor](test/constructor.js)

```javascript
{
        name: 'WithConstructor',
        title: 'my constructor short description',
        description: 'My constructor long long description',
        paramsSeq: [
          'uintParam',
          'stringParam',
          'uintParam2'
        ],
        params: {
          uintParam: {
            name : 'uintParam',
            description: 'Description of item 1',
            type: 'uint',
            typeHint: null
          },
          stringParam: {
            name: 'stringParam',
            type: 'string'
          },
          uintParam2: {
            name : 'uintParam2',
            description: '',
            type: 'uint',
            typeHint: null
          },
        }
}
 ```

### Contract enum structure


Solidity contract  [HasEnum](test/fixture/HasEnum.sol)

```javascript
pragma solidity ^0.4.4;

/**
* Contract has enum
*/
contract HasEnum {

   /**
   * My enum lon long description
   * @dev my enum short description
   * @param item1 Description of item 1
   * @param item2
   * @param item4 Item 4 some description
   */
   enum MyEnum  {
      item1,
      item2,
      item3,
      item4
   }
}
```


Structure of [enum](test/enum.js)

```javascript
{
        MyEnum: {
          name: 'MyEnum',
          title: 'my enum short description',
          description: 'My enum lon long description',
          members: [
            'item1',
            'item2',
            'item3',
            'item4'
          ],
          params: {
            item1: {
              description: 'Description of item 1'
            },
            item2: {
              description : ''
            },
            item4: {
              description: 'Item 4 some description'
            }
          }

        }
}
```

Other examples can be found in [tests](test/)

---
_Source: https://npm.io/package/solidity-structure · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
