typescript - อาร์กิวเมนต์ของประเภท '{ value: BigNumber; }' ไม่สามารถกำหนดค่าให้กับพารามิเตอร์ของประเภท 'Overrides & { from?: string | Promise | undefined; }' ได้
ฉันกำลังพัฒนาสมาร์ทคอนแทร็กต์ด้วย Solidity (เวอร์ชัน 0.8.0) ที่ buildspace นี่คือโค้ดตัวอย่างของฉันใน TypeScript (4.5.x)/JavaScript และ node 16.13.x
...
const waveContractFactory = await hre.ethers.getContractFactory("WavePortal");
const waveContract = await waveContractFactory.deploy({
value: hre.ethers.utils.parseEther("0.1"),
});
...โค้ดด้านบนถูกเขียนไว้ในไฟล์ที่ชื่อว่า: run.ts ในการรันโค้ดนี้ คำสั่งคือ: npx hardhat run scripts/run.ts
นี่คือหัวของข้อผิดพลาดที่ฉันได้รับโดยมีส่วนท้ายถูกตัด:
error TS2345: Argument of type '{ value: BigNumber; }' is not assignable to parameter of type 'Overrides & { from?: string | Promise<string> | undefined; }'.
Object literal may only specify known properties, and 'value' does not exist in type 'Overrides & { from?: string | Promise<string> | undefined; }'.
7 value: hre.ethers.utils.parseEther("0.1"),
....
โดยมี "7" ข้างบนแสดงบรรทัดที่เกิดข้อผิดพลาด
ฉันไม่รู้ว่าข้อผิดพลาดมาจากไหน โค้ดยังคงล้มเหลวสำหรับ run.ts/js
ฉันพยายามที่จะเติมเงินให้กับสมาร์ทคอนแทรกต์ของฉันด้วย 0.1 อีเธอร์
นี่คือตัวอย่างโค้ดของสัญญาอัจฉริยะของฉัน:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract WavePortal {
...
constructor() {
console.log("Hello, Multiverse... I am Smart Contract WavePortal");
}
...
}
คำตอบ #1
ดังนั้นหลังจากทำการค้นคว้ามาหลายชั่วโมง ฉันก็พบคำตอบที่นี่
ฉันต้องเพิ่มตัวแก้ไข payable ให้กับตัวสร้างของสัญญาและมันทำงาน:
contract WavePortal {
...
constructor() payable {
console.log("Hello, Multiverse... I am Smart Contract WavePortal");
}
...
}
