-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5922 from NomicFoundation/chore/add-mainnet-op-sc…
…ript-to-templates chore: add optimism example script to viem template
- Loading branch information
Showing
4 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
v-next/hardhat/templates/node-test-runner-viem/scripts/deploy-counter-contract.ts
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
v-next/hardhat/templates/node-test-runner-viem/scripts/send-op-tx.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { network } from "@ignored/hardhat-vnext"; | ||
|
||
const { viem, networkConfig, networkName } = await network.connect( | ||
undefined, | ||
"optimism", | ||
); | ||
|
||
console.log("Sending transaction using network", networkName); | ||
|
||
if (networkConfig.type === "edr") { | ||
console.log("Using an EDR network simulating Optimism, forking it"); | ||
} else { | ||
console.log("Using an HTTP connection to Optimism"); | ||
} | ||
|
||
const publicClient = await viem.getPublicClient(); | ||
const [senderClient] = await viem.getWalletClients(); | ||
|
||
console.log("Sender:", await senderClient.account.address); | ||
|
||
console.log( | ||
"Sender balance:", | ||
await publicClient.getBalance(senderClient.account), | ||
); | ||
|
||
console.log("Sending 1 wei from", senderClient.account.address, "to itself"); | ||
|
||
console.log("Estimating L1 gas first"); | ||
const l1Gas = await publicClient.estimateL1Gas({ | ||
account: senderClient.account.address, | ||
to: senderClient.account.address, | ||
value: 1n, | ||
}); | ||
|
||
console.log("Estimated L1 gas:", l1Gas); | ||
|
||
console.log("Sending L2 transaction"); | ||
const tx = await senderClient.sendTransaction({ | ||
to: senderClient.account.address, | ||
value: 1n, | ||
}); | ||
|
||
const receipt = await publicClient.waitForTransactionReceipt({ hash: tx }); | ||
|
||
console.log("Transaction receipt:", receipt); |