본문 바로가기

Hardhat

[Hardhat] .deploy VS .deployed

contract 배포할 때 어떤 코드는 .deploy 까지만 하고 어떤 코드는 .deploy 이후에 .deployed 까지 해줘서 뭐가 다른걸까 궁금했다.

 

내 테스트코드의 일부다.

GachaCard = await ethers.getContractFactory("GachaCard");
gachaCard = await GachaCard.deploy(
  FIRST_MINT_PRICE,
  MINT_PRICE,
  FIRST_MINT_AMOUNT
);
await gachaCard.deployed();

.deploy()는 이 컨트랙트 배포를 트리거하고

.deployed()는 컨트랙트가 이미 블록체인에서 사용 가능한지 확인하고 배포가 아직 진행 중이면 배포 트랜잭션이 채굴될 때까지 기다린다.

 

.deployed()는 컨트랙트가 제대로 배포되었는지 확인하고 이제 스크립트에서 추가로 상호작용할 준비가 되었는지 확인하는 데 도움이 된다.

 

.deploy()가 실제 배포를 처리하는 반면,

.deployed()는 deployTransaction.wait()를 호출하여 블록 확인을 기다리며, 컨트랙트가 배포되지 않은 경우 오류를 기록할 수도 있다.

 

배포에 관한한 이중 확인은 항상 좋은 습관이기에 오류를 방지하기 위해서는 .deployed script 포함하는 것이 좋다.

 

 

[출처]

https://ethereum.stackexchange.com/questions/117885/differences-between-deploy-and-deployed-methods

 

Differences between .deploy() and deployed() methods

I am writing a js script that deploy my solidity contract. In the tuto, they use two methods .deploy() and .deployed() const main = async () => { const [owner, randomPerson] = await hre.ethers.

ethereum.stackexchange.com