4.0.30 ā€¢ Published 5 years ago

truffle-artifactor v4.0.30

Weekly downloads
515
License
MIT
Repository
github
Last release
5 years ago

truffle-artifactor

This package saves contract artifacts into JSON files

const Artifactor = require("truffle-artifactor");
const artifactor = new Artifactor(__dirname);
artifactor.save({/*...*/}); // => a promise saving MyContract.json to a given destination

šŸ‘

Features

  • Manages contract ABIs, binaries and deployed addresses, so you don't have to.
  • Packages up build artifacts into .json files, which can then be included in your project with a simple require.
  • Manages library addresses for linked libraries.

The artifactor can be used with truffle-contract, which provides features above and beyond web3:

  • Synchronized transactions for better control flow: transactions won't be considered finished until you're guaranteed they've been mined.
  • Promises. No more callback hell. Works well with ES6 and async/await.
  • Default values for transactions, like from address or gas.
  • Returning logs, transaction receipt and transaction hash of every synchronized transaction.

Install

$ npm install truffle-artifactor

Example

Here, we'll generate a .json files given a JSON object like @truffle/contract-schema. This will give us a file which we can later require into other projects and contexts.

const Artifactor = require("truffle-artifactor");
const artifactor = new Artifactor(__dirname);

// See truffle-schema for more info: https://github.com/trufflesuite/truffle/tree/develop/packages/contract-schema
const contractData = {
  contractName: "...",        // String; optional.
  abi: ...,                   // Array; required.
  metadata: "...",            // String; optional.
  bytecode: "...",            // String; optional.
  "x-some-dependency": ...    // String, Number, Object, or Array: optional.
};

artifactor.save(contractData);
// The file ./MyContract.json now exists, which you can
// import into your project like any other Javascript file.

API

artifactor.save(contractData)

Save contract data as a .json file. Returns a Promise.

  • contractData: Object. Data that represents this contract:

    {
      contractName: "MyContract",   // String; optional. Defaults to "Contract".
      abi: ...,                     // Array; required.  Application binary interface.
      metadata: "...",              // String; optional. Contract metadata.
      bytecode: "...",              // String; optional. Contract-creation binary without resolve library links.
      deployedBytecode: "...",      // String; optional. On-chain deployed binary without resolve library links.
      sourceMap: "...",             // String; optional. Source mapping for bytecode.
      deployedSourceMap: "...",     // String; optional. Source mapping for deployedBytecode.
      source: "...",                // String; optional. Uncompiled source code for contract.
      sourcePath: "...",            // String; optional. File path for uncompiled source code.
      ast: ...,                     // Object; optional. JSON representation of contract source code, as output by compiler.
      legacyAST: ...,               // Object; optional. Legacy JSON representation of contract source code, as output by compiler.
      compiler: ...,                // Object; optional. Compiler "type" and "properties".
      networks: ...,                // Object; optional. Mapping of network ID keys to network object values (address information, links to other contract instances, and/or contract event logs).
      schemaVersion: "...",         // String; optional. Schema version used by contract object representation.
      updatedAt: "...",             // String; optional. Time contract object representation was generated/most recently updated.
      devdoc: "...",                // String; optional. Developer documentation.
      userdoc: "...",               // String; optional. User documentation.
      "x-custom-property": ...      // String, Number, Object, or Array: optional. Custom property. Keys must be prefixed with "x-".
    }

artifactor.saveAll(contracts)

Save many contracts to the filesystem at once. Returns a Promise.

  • contracts: Object. Keys are the contract names and the values are contractData objects, as in the save() function above:

    {
      "MyContract": {
        "abi": ...,
        "bytecode": "..."
      }
      "AnotherContract": {
        // ...
      }
    }

Running Tests

$ npm test

License

MIT

4.0.30

5 years ago

3.0.9

5 years ago

4.0.29

5 years ago

4.0.28

5 years ago

4.0.27

5 years ago

4.0.26

5 years ago

4.0.25

5 years ago

4.0.24

5 years ago

4.0.24-ens.0

5 years ago

4.0.23

5 years ago

4.0.22

5 years ago

4.0.21

5 years ago

4.0.20

5 years ago

4.0.19

5 years ago

4.0.18

5 years ago

4.0.17

5 years ago

4.0.16-alpha.1

5 years ago

4.0.16

5 years ago

4.0.16-beta.1

5 years ago

4.0.16-beta.0

5 years ago

4.0.16-alpha.0

5 years ago

4.0.15

5 years ago

4.0.14

5 years ago

4.0.13

5 years ago

4.0.12

5 years ago

4.0.11

5 years ago

4.0.10

5 years ago

4.0.9

5 years ago

4.0.8

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

3.0.8

5 years ago

4.0.0

5 years ago

4.0.0-beta.2

5 years ago

4.0.0-beta.1

6 years ago

4.0.0-beta.0

6 years ago

3.0.7

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

7 years ago

2.1.5

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago