# @truffle/artifactor

> A contract packager for Ethereum and Javascript

Latest version **4.0.199** (published 2023-09-13) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @truffle/artifactor
pnpm add @truffle/artifactor
yarn add @truffle/artifactor
bun add @truffle/artifactor
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.0.199 |
| Published | 2023-09-13 |
| First published | 2019-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^16.20 \|\| ^18.16 \|\| >=20 |
| Dependencies | 3 |
| Unpacked size | 38.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13904 |
| Author | Tim Coulter |
| Maintainers | rizedr, joshuafernandes, cliffoo, kevinbluer, gnidan, haltman, eggplantzzz, fainashalts, cds-amal |

## Links

- npm: https://www.npmjs.com/package/@truffle/artifactor
- Repository: https://github.com/trufflesuite/truffle
- Homepage: https://github.com/trufflesuite/truffle/tree/master/packages/artifactor#readme
- Issues: https://github.com/trufflesuite/truffle/issues
- npm.io page: https://npm.io/package/@truffle/artifactor

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.1.0
- [@truffle/contract-schema](https://npm.io/package/@truffle/contract-schema.md) ^3.4.16

## Recent versions

- 4.0.199 (latest) — 2023-09-13
- 4.0.188-visual-debugger.0 (visual-debugger) — 2023-05-12
- 4.0.168-hardhat-error.0 (hardhat-error) — 2022-08-25
- 4.0.162-typescript-migrations.0 (typescript-migrations) — 2022-07-21
- 4.0.125-decoder-beta.0 (decoder-beta) — 2021-09-29
- 4.0.122-alpha.1 (eip1559-beta) — 2021-09-13
- 4.0.108-cheerios.1 (cheerios) — 2021-06-10
- 4.0.108-decoder-no-web3.0 (decoder-no-web3) — 2021-06-09
- 4.0.82-abi-utils.0 (abi-utils) — 2020-10-12
- 4.0.70-save-intermediate.1 (save-intermediate) — 2020-07-31
- 4.2.0-tezos.13 (tezos) — 2020-07-15
- 4.0.66-preserves.8 (preserves) — 2020-07-14
- 4.0.67-next.0 (next) — 2020-07-09
- 4.0.51-truffleLogger.0 (truffleLogger) — 2020-03-04
- 4.0.49-alphaTez.0 (alphaTez) — 2020-02-17
- … 235 more at https://npm.io/package/@truffle/artifactor/versions

## README

# @truffle/artifactor

This package saves contract artifacts into JSON files

```javascript
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](https://github.com/trufflesuite/truffle/tree/develop/packages/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](https://github.com/trufflesuite/truffle/tree/develop/packages/contract-schema). This will give us a file which we can later `require` into other projects and contexts.

```javascript
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:

    ```javascript
    {
      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 | Array). If an object is passed, the keys are the
    contract names and the values are `contractData` objects, as in the `save`
    function above. If an Array is used, the members are `contractData` objects
    as in the `save` function above.

    ```javascript
    {
      MyContract: {
        abi: "...",
        bytecode: "...",
        // ...
      },
      AnotherContract: {
        abi: "...",
        bytecode: "...",
        // ...
      }
    }
    ```
    or
    ```javascript
    [
      {
        contract_name: "MyContract",
        abi: "...",
        bytecode: "...",
        // ...
      },{
        contract_name: "AnotherContract",
        abi: "...",
        bytecode: "...",
        // ...
      }
    ]
    ```

### Running Tests

```
$ npm test
```

### License

MIT

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