-
Notifications
You must be signed in to change notification settings - Fork 128
Why can't I get a contract address #105
Comments
Can you help me? |
if i this, will be so i want to know how can i do |
i also have this error, contract don't have this property |
here is a answer |
but i want to get the contract address。 |
You can get the contract address like so:
or like so:
Preferably the second option. |
...
const ethers = require("ethers");
const fs = require("fs-extra");
require("dotenv").config();
async function main() {
// http://127.0.0.1:7545
// console.log(process.env.PRIVATE_KEY);
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
// const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
// let wallet = await ethers.Wallet.fromEncryptedJsonSync(
// encryptedJson,
// process.env.PRIVATE_KEY_PASSWORD
// );
// wallet = await wallet.connect(provider);
const abi = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.abi",
"utf8"
);
const binary = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("部署中,请稍等...");
const contract = await contractFactory.deploy();
// await contract.deployTransaction.wait(1);
await contract.deploymentTransaction().wait(1);
console.log(
Contract Address:${contract.address}
);//Get number
const currentFavoriteNumber = await contract.retrieve();
console.log(
Current Favorite NUmber: ${currentFavoriteNumber.toString()}
);const transactionResponse = await contract.store("7");
const transactionReceipt = await transactionResponse.wait(1);
const updatedFavoriteNumber = await contract.retrieve();
console.log(
Updated favorite number is: ${updatedFavoriteNumber}
);}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
...
Here's my result:
部署中,请稍等...
Contract Address:undefined
Current Favorite NUmber: 0
The text was updated successfully, but these errors were encountered: