这是我的01部署-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"]这是我在registerVault中的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;
}那是我的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"
}
}当我运行“纱线硬帽子部署”时,出现了一个TypeError:
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)
....当我添加“等待btc_eth.deployed()”并运行“纱线硬帽子部署”时,出现了另一个错误:
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)
``发布于 2023-04-09 06:23:56
deploy函数返回一个部署对象,但您希望与契约实例进行交互。
将此等待btc_eth.deployed()替换为const btc_eth_contract = await ethers.getContractAt("CrossChain", btc_eth.address);
然后像这样修改所有实例:
async function submitTransaction() {
const web3 = new Web3(window.ethereum);
const contractAddress = '0x9d405a1d409f32867508fd3460f7d4708bf9ebba';
const contractABI = [...];
const contract = new web3.eth.Contract(contractABI, contractAddress);
const accounts = await web3.eth.getAccounts();
const gasPrice = await web3.eth.getGasPrice();
const currentOwner = await contract.methods.getCurrentOwner().call();
const gasEstimate = await contract.methods.verifyOwnership().estimateGas();
const transaction = {
from: currentOwner,
to: contractAddress,
gas: gasEstimate,
gasPrice: gasPrice,
data: contract.methods.verifyOwnership().encodeABI()
};
const result = await web3.eth.sendTransaction(transaction);
console.log(result);
}https://ethereum.stackexchange.com/questions/148693
复制相似问题