Closed emclab closed 3 years ago
It looks like I forgot to tag that sample code as javascript
, so the code failed to execute. I'll update that now.
To override the nonce in a deployment, you would do:
const overrides = {
nonce: 1234
};
const contract = await factory.deploy("ricmoo.eth", 42, overrides);
Overrides always behave like the normal optional options
parameter that are common in JavaScript, It's just the last parameter after all required parameters. :)
I've updated the docs a bit: https://docs.ethers.io/v5/api/contract/contract-factory/
I'm hoping to get some time to flesh out the docs quite a bit more in December. :)
@ricmoo , thank you again for answer with details .
Hello @ricmoo , in the just updated the code example under contract.deployTransaction
, is the output nonce:6
assigned by deployTransaction
randomly when the transaction was submitted to network? There is no overrides
defined when factory.deploy
. My understanding about transaction nonce for dapp is that dapp is responsible to manage transaction nonce.
The nonce if not specified is fetched from the network for signers that don’t manage nonces themselves (such as Wallet or Hardware wallets), but some Signers manage it themselves, such as MetaMask.
So, it depends. But ethers will take care of it for you when it can (if you don’t override it). :)
Does that help?
The updated code is as below:
const factory = new ContractFactory(abi, bytecode, wallet); //the provider for wallet is pointing to a ethereum node on public internet
var overrides = {
nonce: 0
};
const contract = await factory.deploy(overrides); //<<==this line never returned anything or even throwing error. No code after that was executed.
The contract was successfully deployed to ganache
network (url is http://localhost:8545). But when deployed to a ethereum node (url: http://node-public-ip:8545. verified up and running), the line of const contract = await factory.deploy(overrides)
never returned anything. How factory.deploy
shall behave if the execution get wrong somehow (such as ethereum node was not functioning as normal or params passed is not right)?
The nonce if not specified is fetched from the network for signers that don’t manage nonces themselves (such as Wallet or Hardware wallets), but some Signers manage it themselves, such as MetaMask.
So, it depends. But ethers will take care of it for you when it can (if you don’t override it). :)
Does that help?
Absolutely! In your opinion, shall the dapp leave transaction nonce for etherjs to manage? I would be extremely relieved if I don't need code for nonce management.
Here is the example code from doc of contract deployment. Where can I add transaction nonce to the transaction of deploying contract?