etherjs (5.0) is used to deployed a smart contract Hello.sol. Here is the js code (truffle 5.1.52/ganache CLI 6.12.1):

  import { ContractFactory, ethers } from "ethers";

  let privateKey = "0xf43608a210da70d40115ad23526e50f2a502c018aeffd56477fcbe44119b53cc"; //<<==private key from ganache-cli
  let wallet = new ethers.Wallet(privateKey);  //address of the wallet
  console.log("wallet : ", wallet);
  const factory = new ContractFactory(abi, bytecode, signer); //<<==abi, bytecode, signer defined before
  const contract = await factory.deploy(wallet.address);
  console.log("contract deployed : ", contract);
  console.log("contract address : ", contract.address);
  // The transaction that the signer sent to deploy
  // Wait until the transaction is mined

The execution of code above generates the output on ganache-cli -b 3:

  Transaction: 0x5c626a276ba9ddf0b0b69c4fab774b5ac2e8026fe7dd0bb149b4939a2b1ca25d
  Contract created: 0xaec5a7f864e3e5e42554b5d645f62ba07add7517
  Gas usage: 122107
  Block Number: 1075
  Block Time: Sun Nov 15 2020 13:15:03 GMT-0800 (Pacific Standard Time)


The contract is deployed at the address of 0xaec5a7f864e3e5e42554b5d645f62ba07add7517. Then launching truffle development and hello = await Hello.at("0xaec5a7f864e3e5e42554b5d645f62ba07add7517") returns the instance of the contract deployed. The problem is that after Hello.sol is updated with addition of 2 functions, now the hello = await... returns an error:

truffle(develop)> hello = await Hello.at("0xaec5a7f864e3e5e42554b5d645f62ba07add7517")
Error: Cannot create instance of Hello; no code at address 0xaec5a7f864e3e5e42554b5d645f62ba07add7517
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Function.at (C:\D\code\js\node_modules\truffle\build\webpack:\packages\contract\lib\contract\constructorMethods.js:74:1)
    at Object.checkCode (C:\D\code\js\node_modules\truffle\build\webpack:\packages\contract\lib\utils\index.js:265:1)

Here is the step the Hello.sol was updated:

  1. function setValue and getValue were added to the contract in remix
  2. compile successfully with abi and bytecode
  3. update the Hello.sol in VS code
  4. run truffle compile successfully
  5. After deploying the contract in VS code, use the contract address returned in ganache to make connection in truffle development

What is wrong causing the contract is not at the address returned by ganache after update?

UPDATE:here is the part of the truffle-config.js:

networks: {
      development: {
        host: "localhost",
        port: 8545,  //testing
        network_id: "*" // Match any network id
  • 1
    Is truffle connected to the same ganache instance? Check the networks section in truffle-config.js file matches ganache instance. – Ismael Nov 16 '20 at 18:01
  • Just updated with networks:development in truffle-config.js. It is connected to port 8545 on localhost. – user938363 Nov 17 '20 at 0:49
  • Check again if you are using the right network develop != development. To pass the correct network is something like this: truffle console --network development. – Ismael Nov 18 '20 at 1:54

Your Answer

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

Browse other questions tagged or ask your own question.