Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Environment script to be ran by Truffle when starting a console. #2472

Closed
1 task done
hickscorp opened this issue Oct 18, 2019 · 10 comments
Closed
1 task done

Environment script to be ran by Truffle when starting a console. #2472

hickscorp opened this issue Oct 18, 2019 · 10 comments

Comments

@hickscorp
Copy link

Note that this is not an issue, but rather a feature request. I asked a question on the Truffle's Gitter and I was pointed at opening an issue here.

The original question was:

Is there a way to have a script ran in the same scope at the truffle console every time it loads? I would like to have some functions and stuff ready automatically whenever I enter truffle console.

Let me expand on that - when in a truffle console, it'd be great to have a way to have some "environmental" setup done per-project. For instance, having a set of functions automatically loaded from a module. From this standpoint, the module would expose a function that would receive important things (Like a regular Truffle script) - one of the important one being artifacts.

@gnidan
Copy link
Contributor

gnidan commented Oct 21, 2019

Hm we can probably hook up the truffle exec plumbing to this. What would this be... a config option?

module.exports = {
  /* ... rest of config ... */
  console: {
    exec: "<path/to/script.js>"
  }
}

something like that maybe?

@hickscorp
Copy link
Author

@gnidan I think your suggestion is pretty much what would be needed for a first iteration - as long as the script receives proper environment (particularly artifacts).

@hickscorp
Copy link
Author

Bump - was there any progress on this - or similar?

@cds-amal
Copy link
Member

cds-amal commented Jun 7, 2021

This would be a feature I would use! @gnidan would love to discuss progressing this.

@hickscorp
Copy link
Author

For example, every single time I open my truffle console, I have to copy-paste this in it:

const BN = require('bn.js');
const generateUtils = require('./scripts/utils.js')
const netId = process.env.NETWORK_ID
const zosFile = `.openzeppelin/dev-${netId}.json`
const zosAbi = JSON.parse(fs.readFileSync(zosFile))
const people = Object.assign(require(`./conf/addresses.${netId}`), require(`./conf/addresses.private.${netId}`))
const governance = { from: people.pk2m }
const issuance = { from: people.issuer }
const registry = await Registry.at(zosAbi.proxies[`TTContracts/Registry`][0].address)
const access = await Access.at(zosAbi.proxies[`TTContracts/Access`][0].address)
const register = await Register.at(zosAbi.proxies[`TTContracts/Register`][0].address)
const transact = await Transact.at(zosAbi.proxies[`TTContracts/Transact`][0].address)
const token = await Token.at(zosAbi.proxies[`TTContracts/Token`][0].address)

Then I have to wait for all the promises to resolve, and then paste this in it:

const utils = generateUtils(registry, access, register, transact, token)

It'd be nice to have a JS or TS script "sourced" by Ganache console.

@cds-amal
Copy link
Member

@hickscorp Thanks for bumping this! I want to have this as well.

@haltman-at
Copy link
Contributor

OK, I'm going to close this now that #4127 is released. I'm not certain that #4127 is quite enough for everything you wanted, but feel free to open a new issue (or I might if you don't :) ).

@cds-amal
Copy link
Member

cc: @hickscorp

@haltman-at
Copy link
Contributor

OK, I've opened #4174 and #4175 to track the follow-on work here.

@hickscorp
Copy link
Author

@cds-amal and @haltman-at Just realised that there were progress on this outside of this issue. I'll check and see if it's suitable.
Thanks a lot guys.

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

No branches or pull requests

6 participants