openzeppelin-cli uses the wrong account
I noticed an odd behavior while using openzeppelin-cli where it uses the account in the list that @truffle/hdwallet-provider provides no matter what account was actually selected.
I'm using @openzeppelin/cli version 2.8.2 and @truffle/hdwallet-provider version 1.0.42
Here is my networks.js:
const { infuraId, alchemyId, mnemonic } = require('./secrets.json');
const HDWalletProvider = require('@truffle/hdwallet-provider');
module.exports = {
networks: {
development: {
protocol: 'http',
host: 'localhost',
port: 8545,
gas: 5000000,
gasPrice: 5e9,
networkId: '*',
},
goerli_infura: {
provider: () => new HDWalletProvider(
mnemonic, `https://goerli.infura.io/v3/${infuraId}`
),
networkId: 5,
gasPrice: 2e9
},
rinkeby_infura: {
provider: () => new HDWalletProvider(
mnemonic, `https://rinkeby.infura.io/v3/${infuraId}`
),
networkId: 4,
gasPrice: 10e9
},
rinkeby_alchemy: {
provider: () => new HDWalletProvider(
mnemonic, `https://eth-rinkeby.alchemyapi.io/v2/${alchemyId}`
),
networkId: 4,
gasPrice: 10e9
},
rinkeby_local: {
provider: () => new HDWalletProvider(
mnemonic, `http://172.27.96.1:8545`
),
networkId: 4,
gasPrice: 10e9
}
},
};
Here is how I deploy a contract
This is what the node says:
INFO [08-27|15:00:14.450] Submitted contract creation fullhash=0x############################################################0fa7 contract=0x########################################
And this is what etherscan says:

I don't really know if the issue is with openzeppelin-cli or with @truffle/hdwallet-provider
So. I modified networks.js to this:
rinkeby_local: {
provider: () => new HDWalletProvider(
mnemonic, `http://172.27.96.1:8545`, 2 // <-- added 1 more argument
),
networkId: 4,
gasPrice: 10e9
}
I did this so that HDWalletProvider starts generating accounts from 2 (zero indexed). I then selected account 0 and deployed.
This whole thing worked and the contract was deployed from the correct account.
I'm not really sure what the culprit is. I'm thinking it might be @truffle/hdwallet-provider or even @openzeppelin/cli
Hi @nicexe! I’m sorry that you had this issue.
We have been able to reproduce this issue by following these steps:
- Set a session
$ npx oz session
? Pick a network rinkeby
? Enter a timeout in seconds to use for http-based web3 transactions 750
? Enter a timeout in blocks to use for websocket-based web3 transactions 50
? Choose the account to send transactions from (1) 0x059aE37646900CaA1680473d1280246AfCCC3114
? Enter an expiration time for this session (in seconds) 3600
Using network rinkeby, sender address 0x059aE37646900CaA1680473d1280246AfCCC3114, timeout 750 seconds, blockTimeout 50 blocks by default.
- Deploy a regular contract
$ npx oz deploy --network rinkeby
Nothing to compile, all contracts are up to date.
? Choose the kind of deployment regular
Using session with network rinkeby, sender address 0x059aE37646900CaA1680473d1280246AfCCC3114, timeout 750 seconds, blockTimeout 50 blocks
? Pick a contract to deploy Box
✓ Deployed instance of Box
0x3FaFDb81B9DAC664B4e1F2b276865AC6bC94eC65
But the contract is actually deployed from the default account. See: https://rinkeby.etherscan.io/address/0x3FaFDb81B9DAC664B4e1F2b276865AC6bC94eC65
$ npx oz accounts
Using session with network rinkeby, sender address 0x059aE37646900CaA1680473d1280246AfCCC3114, timeout 750 seconds, blockTimeout 50 blocks
Accounts for rinkeby:
Default: 0x77737a65C296012C67F8c7f656d1Df81827c9541
All:
- 0: 0x77737a65C296012C67F8c7f656d1Df81827c9541
- 1: 0x059aE37646900CaA1680473d1280246AfCCC3114
Thanks so much for reporting it! The project owner will review and triage this issue as soon as they can. In the meantime, you can try the following workaround:
Instead of session you can use oz deploy --from to specify the account (as I suspect that the new deploy doesn't appropriately use `session)
https://docs.openzeppelin.com/cli/2.8/commands#deploy
$ npx oz deploy --network rinkeby --from 0x059aE37646900CaA1680473d1280246AfCCC3114
Nothing to compile, all contracts are up to date.
? Choose the kind of deployment regular
Using session with network rinkeby, sender address 0x059aE37646900CaA1680473d1280246AfCCC3114, timeout 750 seconds, blockTimeout 50 blocks
? Pick a contract to deploy Box
✓ Deployed instance of Box
0x0d0FE29b73793370cF54c4Cb549d683c985C2B48
The contract is deployed using the specified account: https://rinkeby.etherscan.io/address/0x0d0FE29b73793370cF54c4Cb549d683c985C2B48