That's my 01-deploy-main.js
const { network, ethers } = require("hardhat")
const { developmentChains } = require("../helper-hardhat-config")
const { relayNetworks } = require("../btcrelay-config")
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer, vault, alice, bob, eve } = await getNamedAccounts()
let args
let btc_eth
if (developmentChains.includes(network.name)) {
const btcRelay = await deployments.get("MockBTCRelay")
args = ["BTC-ETH-CROSS", "BTH", 1, btcRelay.address]
btc_eth = await deploy("CrossChain", {
from: deployer,
log: true,
args: args,
})
} else if (network.name == "sepolia") {
args = ["BTC-ETH-CROSS", "BTH", 1, relayNetworks.sepolia]
btc_eth = await deploy("CrossChain", {
from: deployer,
log: true,
args: args,
})
} else if (network.name == "main") {
args = ["BTC-ETH-CROSS", "BTH", 1, relayNetworks.main]
btc_eth = await deploy("CrossChain", {
from: deployer,
log: true,
args: args,
})
}
await btc_eth.deployed()
log(`Got cotract CrossChain at ${btc_eth.address}`)
log("CrossChain deployed!")
log("--------------------------------------------------")
const amount = 1
const collateral = "0.01"
const collateral_user = "0.00000001"
let vault_collateral = ethers.utils.parseUnits(collateral, "ether")
let user_collateral = ethers.utils.parseUnits(collateral_user, "ether")
const btc_address_vault = "0x02a751dc8c10e35fed2c6eddc2575c9af2c71d23"
const btc_address_bob = "0x69f374b39af4aa342997e0bdff3b3b297a85883c"
const btc_tx =
"0x3a7bdf6d01f068841a99cce22852698df8428d07c68a32d867b112a4b24c8fe0"
const gas_limit = 6000000
await btc_eth.registerVault(vault, {
from: vault,
value: vault_collateral,
})
btc_eth.once("RegisterVault", (from, value) => {
console(
`vault ${vault.address} successfully registered and the vault_collteral is ${vault_collateral}!`
)
})
}
module.exports.tags = ["all", "btc_eth"]
That's my registerVault function in Treasury.sol
function registerVault(
address payable toRegister
) public payable override returns (bool) {
require(msg.value >= _minimumCollateralVault, "Collateral too low");
_registerNewVault(toRegister, msg.value);
_vaultTokenSupply += _convertEthToBtc(msg.value);
_vaultCollateral += msg.value;
return true;
}
That's my package.json
{
"name": "hardhat-cross-chain",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@chainlink/contracts": "^0.6.1",
"@ethersproject/abi": "^5.4.7",
"@ethersproject/providers": "^5.4.7",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
"ethers": "5.7.0",
"fs-extra": "^11.1.1",
"hardhat": "^2.13.0",
"hardhat-deploy": "^0.11.25",
"hardhat-gas-reporter": "^1.0.8",
"openzeppelin-solidity": "^3.4.2",
"prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.1.3",
"solhint": "^3.4.1",
"solidity-coverage": "^0.8.0",
"typechain": "^8.1.0"
},
"scripts": {
"test": "hardhat test",
"test:staging": "hardhat test --network sepolia",
"lint": "solhint 'contracts/**/*.sol'",
"lint:fix": "solhint 'contracts/**/*.sol' --fix",
"format": "prettier --write .",
"coverage": "hardhat coverage"
}
}
When I run "yarn hardhat deploy", a TypeError occured:
Nothing to compile
Local network detected! Deploying mocks...
deploying "MockBTCRelay" (tx: 0x191f0c3fe1817cf0bac4f9e69b2f00a14fedc895d255d735c860ae7601631550)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 606889 gas
Got contract MocjBTCRelay at 0x5FbDB2315678afecb367f032d93F642f64180aa3
Mocks deployed!
--------------------------------------------------
deploying "CrossChain" (tx: 0x199057c66a9a92a7fe99999b51fb7af96e89b2f1de265d6de1373f2c07278d72)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 5864917 gas
An unexpected error occurred:
Error: ERROR processing C:\Users\86186\Desktop\Blockchain\Ethereum\Project\hardhat-cross-chain\deploy\01-deploy-main.js:
TypeError: btc_eth.deployed is not a function
at Object.module.exports [as func] (C:\Users\86186\Desktop\Blockchain\Ethereum\Project\hardhat-cross-chain\deploy\01-deploy-main.js:75:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at runNextTicks (internal/process/task_queues.js:62:3)
at listOnTimeout (internal/timers.js:523:9)
at processTimers (internal/timers.js:497:7)
....
and when I add "await btc_eth.deployed()", and run "yarn hardhat deploy", another error occured:
Nothing to compile
Local network detected! Deploying mocks...
deploying "MockBTCRelay" (tx: 0x191f0c3fe1817cf0bac4f9e69b2f00a14fedc895d255d735c860ae7601631550)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 606889 gas
Got contract MocjBTCRelay at 0x5FbDB2315678afecb367f032d93F642f64180aa3
Mocks deployed!
--------------------------------------------------
deploying "CrossChain" (tx: 0x199057c66a9a92a7fe99999b51fb7af96e89b2f1de265d6de1373f2c07278d72)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 5864917 gas
Got cotract CrossChain at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
CrossChain deployed!
--------------------------------------------------
An unexpected error occurred:
Error: ERROR processing C:\Users\86186\Desktop\Blockchain\Ethereum\Project\hardhat-cross-chain\deploy\01-deploy-main.js:
TypeError: btc_eth.registerVault is not a function
at Object.module.exports [as func] (C:\Users\86186\Desktop\Blockchain\Ethereum\Project\hardhat-cross-chain\deploy\01-deploy-main.js:93:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at runNextTicks (internal/process/task_queues.js:62:3)
at listOnTimeout (internal/timers.js:523:9)
at processTimers (internal/timers.js:497:7)
...
I encountered this error when deploying contracts using hardhat and ethers: "TypeError: btc_eth.deployed is not a function". Please help me
I have successfully solved this problem! The deploy function returns a deployment object, but I want to interract with the contract instance.