Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
How is hardhat implicitly knowing deployer address?

I am new to using hardhat and I was trying to figure out how it is working. The documentation seems a little bit fuzzy as there are multiple layers of abstractizations and I don't understand how is the ethers.getSigners() using my private key. Is it implicitly using the hardhat config file defined in the root of my directory? Also is hardhat project structure predefined and enforced? If not, how does getContractFactory know where to look for the artifact?

const { ethers } = require("hardhat");

async function main() {
    const [deployer] = await ethers.getSigners();
    console.log("Account balance:", (await deployer.getBalance()).toString());

    const VendingMachine = await ethers.getContractFactory("VendingMachine")
    const vendingMachine = await VendingMachine.deploy()
    await vendingMachine.deployed()

    console.log("Contract deployed to address:", vendingMachine.address)
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Hardhat node uses a default mnemonic phrase (docs) that can be derived into multiple pairs of private/public keys (20 by default). These accounts are unlocked at the local node.

Your snippet uses the ethers NPM package (imported by hardhat) that uses the first unlocked account to send transactions from (including deployment transactions), unless specified otherwise.

The project structure (e.g. contracts and test folders) is defined by the Hardhat framework - but you can change the default folder structure to a custom one (docs).

about 4 years ago · Juan Pablo Isaza Relatório

0

Hardhat is a great tool that has some premade configuration to make the development easy, hardhat automatically injects the signers data to their version of ethers, in that way you automatically have the default signers or one made with the private keys or mnemonic that you can define in the hardhat config, if you don't select an specific signer when you create a contract instance hardhat is also smart enough to select the first item in the signer array.

About the getContractFactory, hardhat have some predifined routes to store the compiled contract data, but this can be overwrite in the hardhat config if you wish to, that way hardhat knows where to look for the data you are asking for

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda