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);
//deploy
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
contract.deployTransaction;
// Wait until the transaction is mined
contract.deployTransaction.wait();
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)
eth_blockNumber
eth_chainId
eth_getTransactionReceipt
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")
Uncaught:
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:
- function
setValue
andgetValue
were added to the contract in remix - compile successfully with abi and bytecode
- update the
Hello.sol
in VS code - run
truffle compile
successfully - After deploying the contract in VS code, use the contract address returned in
ganache
to make connection intruffle 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
}
},
truffle-config.js
file matches ganache instance. – Ismael Nov 16 '20 at 18:01truffle console --network development
. – Ismael Nov 18 '20 at 1:54