Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

README outdated? #49

Open
jtakalai opened this issue Mar 31, 2017 · 7 comments
Open

README outdated? #49

jtakalai opened this issue Mar 31, 2017 · 7 comments

Comments

@jtakalai
Copy link

It seems truffle-artifactor doesn't work at all as described in the README.md:

var artifactor = require("truffle-artifactor");
artifactor.save({/*...*/}, "./wrappers/MyContract.sol.js") // => a promise

// Later...
var MyContract = require("./wrappers/MyContract.sol.js");

Instead (digging the tests) it seems to work more like this:

var Artifactor = require("truffle-artifactor")
var artifactor = new Artifactor("./wrappers")

artifactor.save({contract_name: "MyContract", /*...*/}) // => a promise

I'm not sure how to write the // Later... part though, since save only seems to generate a .json file, not sol.js. I don't think require("./wrappers/MyContract.json") would be going to do much good...

Any chance README.md could be updated, or at least please point to documentation on how to use truffle-artifactor the way it currently is?

@zmitton
Copy link

zmitton commented Apr 6, 2017

@jtakalai I noticed this too. It saves json files which contain deployment information but mostly they can be used with truffle-contract. Something like this:

//Later...
TruffleContract = require('truffle-contract')
var MyContract = new TruffleContract(require("./wrappers/MyContract.json"));

Now you'd have promisified objects with the api found here

@kevin-smets
Copy link

kevin-smets commented Aug 7, 2017

It does not seem to output any .sol.js file at all? No matter what you try.

I would really like to build the artifact to require later on in the project but it seems the readme does not reflect the correct usage. For now I'll stick to just truffle-contract I guess and do it "realtime".

As far as I can tell, this should work:

  • after deployment using truffle migrate you have ./build/contracts/SimpleStorage.json available
const Artifactor = require("truffle-artifactor");
const artifactor = new Artifactor("./build/contracts");

const contractData = require('./build/contracts/SimpleStorage.json');
const path = require('path');

artifactor
    .save(contractData, path.join(__dirname, 'SimpleStorage.sol.js'))
    .then(function (file) {
        // The file ./SimpleStorage.sol.js should now exist?
    });

@zmitton
Copy link

zmitton commented Aug 7, 2017 via email

@captDaylight
Copy link

captDaylight commented Sep 6, 2017

@zmitton looks like that link isn't working anymore :/

@kevin-smets I had a crack at it after parsing through the tests and got a json file to output using a script like this:

const Artifactor = require('truffle-artifactor');
const path = require('path');
const solc = require('solc');
const fs = require('fs');
const requireNoCache = require('require-nocache')(module);

// Compile first
const result = solc.compile(fs.readFileSync('./MyTest.sol', { encoding: 'utf8' }), 1);

// Clean up after solidity. Only remove solidity's listener,
// which happens to be the first.
process.removeListener('uncaughtException', process.listeners('uncaughtException')[0]);

const compiled = result.contracts[':MyTest']; // not sure why this is getting prepended with :
const abi = JSON.parse(compiled.interface);
const binary = compiled.bytecode;

// Setup
const dirPath = path.resolve('./');
const expected_filepath = path.join(dirPath, 'MyTest.json');

const artifactor = new Artifactor(dirPath);

artifactor.save({
  contract_name: 'MyTest',
  abi,
  binary,
  network_id: 3, // Ropsten
})
  .then(function(result) {
    const json = requireNoCache(expected_filepath);
    console.log(contract(json));
  })
  .catch((error) => {
    console.log('catch error:',error);
  });

@zmitton
Copy link

zmitton commented Sep 8, 2017 via email

@imhari213
Copy link

@kevin-smets I did the same thing what you have suggested in generating ./SimpleStorage.sol.js but it is not generated

@jtakalai
Copy link
Author

Any chance of getting an official fix? I don't mean to belittle @captDaylight's effort, but srsl, the documentation should be the authors' explicit intent on how the library ought to be used, so it should be written by authors themselves. @tcoulter @gnidan?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants