I have split my deployment script in multiple scripts. So, deployed contracts are decoupled and can be combined depending on the target environment. For the hardhat environment, I am trying to run 2 scripts, one after other. Something as:
yarn hardhat run ./scripts/deploy-tokens1.ts
yarn hardhat run ./scripts/deploy-tokens2.ts
Each of these scripts deploys some contracts from the same owner address, something as:
const TokenA = await ethers.getContractFactory("FOO");
const tokenA = await TokenA.deploy("FOO", "FOO");
await tokenA.deployed();
If I run this code within the deploy-tokens1.ts script (the one that created the contract)
const tokenA = await ethers.getContractAt('FOO', 'the_address');
console.log(tokenA.runMethod());
it works and returns [] as expected.
If I run the same code within deploy-tokens2.ts script it fails with:
Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="runMethod()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)
at Logger.makeError (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
at Logger.throwError (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
at Interface.decodeFunctionResult (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/abi/src.ts/interface.ts:427:23)
at Contract.<anonymous> (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/contracts/src.ts/index.ts:400:44)
at step (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/contracts/lib/index.js:48:23)
at Object.next (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/contracts/lib/index.js:29:53)
at fulfilled (/home/pellyadolfo/gasclick-admin/catallactic-suite/node_modules/@ethersproject/contracts/lib/index.js:20:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:540:9) {
reason: null,
code: 'CALL_EXCEPTION',
method: 'runMethod()',
data: '0x',
errorArgs: null,
errorName: null,
errorSignature: null,
address: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
args: [],
transaction: {
data: '0xe676f2a8',
to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
gasLimit: BigNumber { _hex: '0x01bad458', _isBigNumber: true }
}
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
So, somehow both scripts do not have the same context.
Do you know how to run 2+ scripts on hardhat?
My environment:
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@typechain/ethers-v5": "^7.0.1",
"@typechain/hardhat": "^2.3.0",