Truffle Contract Not Deployed Error – Fixed
by Alexandra Kropova from Mammoth Interactive
Trying to Use a Solidity Smart Contract?
Getting the error message “ContractName has not been deployed to detected network (network/artifact mismatch)” ?
Read the solution below!
Want to learn more? Enroll in Beginners Solidity for Ethereum Blockchain Masterclass - Build Smart Contracts. Free in the Mammoth Unlimited Membership. Get 200+ courses and 2,000 hours at a dirt-cheap price.
Your solution:
You must deploy the contract named in the error message. If you already deployed the contract, re-deploy.
To deploy the smart contracts to the Ethereum blockchain, you must first write migrations. In the “migrations” folder of your Truffle project, build a new file “2_deploy_contracts.js”. Truffle migrations enable us to “push” the smart contracts to the blockchain.
const ContractName = artifacts.require("ContractName"); module.exports = function(deployer) { deployer.deploy(ContractName); };
To run the migration script, use the command “npx truffle migrate” in your Terminal/Command Prompt application.
Still not working?
- Make sure a “build” folder has been created and updated when the contract is compiled.
- Make sure you use the contract class name, not the file name.
Suggest more solutions or ask a question in the comments below.
Want to learn more? Enroll in Beginners Solidity for Ethereum Blockchain Masterclass - Build Smart Contracts. Free in the Mammoth Unlimited Membership. Get 200+ courses and 2,000 hours at a dirt-cheap price.