Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"argv": "^0.0.2",
"axios": "^0.21.1",
"dotenv": "^8.0.0",
"ethers": "^5.1.4",
"ethers": "^5.4.2",
"hardhat": "^2.2.1",
"solc": "0.5.8",
"ts-node": "^9.1.1",
Expand Down
11 changes: 7 additions & 4 deletions scripts/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ async function writeFactoryDeployerTransaction(contract: CompilerOutputContract,
const data = arrayFromHexString(deploymentBytecode)

if (!process.env.MNEMONIC) throw Error("MNEMONIC is required")
const signer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC!!)
const signedEncodedTransaction = await signer.signTransaction({
nonce, gasPrice, gasLimit, value, data, chainId
})
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC)
const signer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC!!).connect(provider)
//if the network supports EIP-1559 transaction, use the EIP-1559 transaction type
const tx = await signer.populateTransaction({
nonce, gasPrice, gasLimit, value, data, chainId

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you using EIP-1559 here? You haven't specified the transaction type and you are not using the maxPriorityFeePerGas or maxBaseFeePerGas here, right

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also confused for a while, but the key here seems to be using the .populateTransaction method that adds all the necessary fields, including EIP-1559 gas fields. So the comment could be better 100%.

Also, possibly we'd need to support multiple transaction types because, like networks only supporting eip-1559 transactions, there are networks that only support legacy ones.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, didn't know the populateTransaction method does that by default

@FroghubMan FroghubMan Jun 3, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function sendTransaction in ethers.js' abstract Signer is as follows:

// Populates all fields in a transaction, signs it and sends it to the network
async sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse> {
    this._checkProvider("sendTransaction");
    const tx = await this.populateTransaction(transaction);
    const signedTx = await this.signTransaction(tx);
    return await this.provider.sendTransaction(signedTx);
}

Before signing the transaction, it calls the populateTransaction method to fill in the relevant transaction fields, including the identification of the transaction type. If the type field is not provided, it checks whether the current chain supports EIP-1559. If it does, it populates the maxFeePerGas and maxPriorityFeePerGas fields and generates an EIP-1559 transaction. Otherwise, it generates a Legacy Transaction.

The current adaptation is made to align with the default behavior of the ethers.js library in order to support all EVM-compatible chains.

})
const signedEncodedTransaction = await signer.signTransaction(tx)
const signerAddress = await signer.getAddress()
const contractAddress = ethers.utils.getContractAddress({ from: signerAddress, nonce } )

Expand Down
Loading