I am following the tutorial provided at: Example of Truffle script
But I have added the ganache, compilation and migrate. In migration I am getting the following error: $ truffle exec ts2.js Using network 'ganache'.
Error: Exchange has not been deployed to detected network (network/artifact mismatch)
at Object.checkNetworkArtifactMatch (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/contract/lib/utils/index.js:245:1)
at Function.deployed (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/contract/lib/contract/constructorMethods.js:85:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
My truffle 2_deploy_contracts.js is:
const Exchange = artifacts.require("Exchange");
module.exports = function(deployer) {
deployer.deploy(Exchange);
};
The Exchange contract and the script is provided in the tutorial, I have named the script as ts2 and is copied below:
// Contracts
const Exchange = artifacts.require("Exchange")
// Utils
const ether = (n) => {
return new web3.utils.BN(
web3.utils.toWei(n.toString(), 'ether')
)
}
module.exports = async function(callback) {
try {
// Fetch accounts from wallet - these are unlocked
const accounts = await web3.eth.getAccounts()
// Fetch the deployed exchange
const exchange = await Exchange.deployed()
console.log('Exchange fetched', exchange.address)
// Set up exchange users
const user1 = accounts[0]
// User 1 Deposits Ether
amount = 2
await exchange.depositEther({ from: user1, value: ether(amount) })
console.log(`Deposited ${amount} Ether from ${user1}`)
//...
}
catch(error) {
console.log(error)
}
callback()
}
Somebody please guide me.
Zulfi.