1

When using truffle to migrate smart contracts to Ganache it selects the first address to send the contract and also decrements the gas cost from this address.

How does truffle 'know' to select this address/account? It doesn't seem to be specified anywhere.

Also can it be changed?

| improve this question | | | | |
1

Truffle uses the first account it finds when it inspects the "wallet" which has 10 accounts set up, per ganache's default setup.

According to the docs, it's possible to change behavior.

You can optionally pass an array of contracts, or an array of arrays, to speed up deployment of multiple contracts. Additionally, the last argument is an optional object that can include the key named overwrite as well as other transaction parameters such as gas and from. If overwrite is set to false, the deployer won't deploy this contract if one has already been deployed. This is useful for certain circumstances where a contract address is provided by an external dependency.

https://truffleframework.com/docs/truffle/getting-started/running-migrations

Hope it helps.

| improve this answer | | | | |
  • Thanks - so this is just a kinda nice to have quick solution for testing, in prod, it wouldn't just look at your first account in Geth and use that would it? – Woodstock Sep 12 '18 at 15:11
  • 1
    Yes, it would. It would deploy from the first account, by default. – Rob Hitchens Sep 12 '18 at 15:45
1

Truffle dont need to know this. This is setting of gancahe testrpc chain as taking the first account as default one.

| improve this answer | | | | |
  • Ok thanks - but where is it communicated which address to decrement. Surely when moving to production this needs to be specified? – Woodstock Sep 12 '18 at 14:58
  • 1
    Yes in the production; we dont usually unlock account like this. We will use private key to sign the tnx – Ha ĐANG Sep 12 '18 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.