@truffle/artifactor
This package saves contract artifacts into JSON files
const Artifactor = require("@truffle/artifactor");
const artifactor = new Artifactor(__dirname);
artifactor.save({});
👏
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);
const contractData = {
contractName: "...",
abi: ...,
metadata: "...",
bytecode: "...",
"x-some-dependency": ...
};
artifactor.save(contractData);
API
artifactor.save(contractData)
Save contract data as a .json file. Returns a Promise.
-
contractData: Object. Data that represents this contract:
{
contractName: "MyContract",
abi: ...,
metadata: "...",
bytecode: "...",
deployedBytecode: "...",
sourceMap: "...",
deployedSourceMap: "...",
source: "...",
sourcePath: "...",
ast: ...,
legacyAST: ...,
compiler: ...,
networks: ...,
schemaVersion: "...",
updatedAt: "...",
devdoc: "...",
userdoc: "...",
"x-custom-property": ...
}
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.
{
MyContract: {
abi: "...",
bytecode: "...",
},
AnotherContract: {
abi: "...",
bytecode: "...",
}
}
or
[
{
contract_name: "MyContract",
abi: "...",
bytecode: "...",
},{
contract_name: "AnotherContract",
abi: "...",
bytecode: "...",
}
]
Running Tests
$ npm test
License
MIT