Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.
Closed
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "getting-started/foundry/lib/forge-std"]
path = getting-started/foundry/lib/forge-std
url = https://github.com/foundry-rs/forge-std
2 changes: 0 additions & 2 deletions cross-dom-comm/.env.example

This file was deleted.

3 changes: 3 additions & 0 deletions cross-dom-comm/hardhat/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MNEMONIC= << your value here >>
GOERLI_URL= << your value here >>
OPTI_GOERLI_URL= << your value here >>
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//SPDX-License-Identifier: Unlicense
// This contracts runs on L1, and controls a Greeter on L2.
// The addresses are specific to Optimistic Goerli.
pragma solidity ^0.8.0;

import { ICrossDomainMessenger } from
"@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";

contract ControlL2Greeter {
address crossDomainMessengerAddr = 0x4361d0F75A0186C05f971c566dC6bEa5957483fD;
contract FromL1_ControlL2Greeter {
// Taken from https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts/deployments/goerli#layer-1-contracts
address crossDomainMessengerAddr = 0x5086d1eEF304eb5284A0f6720f79403b4e9bE294;

address greeterL2Addr = 0xD4c204223d6F1Dfad0b7a0b05BB0bCaB6665e0c9;
address greeterL2Addr = 0xC0836cCc8FBa87637e782Dde6e6572aD624fb984;

function setGreeting(string calldata _greeting) public {
bytes memory message;
Expand All @@ -23,4 +25,4 @@ contract ControlL2Greeter {
);
} // function setGreeting

} // contract ControlL2Greeter
} // contract FromL1_ControlL2Greeter
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//SPDX-License-Identifier: Unlicense
// This contracts runs on L2, and controls a Greeter on L1.
// The greeter address is specific to Goerli.
pragma solidity ^0.8.0;

import { ICrossDomainMessenger } from
"@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";

contract ControlL1Greeter {
contract FromL2_ControlL1Greeter {
// Taken from https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts/deployments/goerli#layer-2-contracts
// Should be the same on all Optimism networks
address crossDomainMessengerAddr = 0x4200000000000000000000000000000000000007;

address greeterL1Addr = 0x11fB328D5Bd8E27917535b6d40b881d35BC39Be0;
address greeterL1Addr = 0x7fA4D972bB15B71358da2D937E4A830A9084cf2e;

function setGreeting(string calldata _greeting) public {
bytes memory message;
Expand All @@ -23,4 +26,4 @@ contract ControlL1Greeter {
);
} // function setGreeting

} // contract ControlL1Greeter
} // contract FromL2_ControlL1Greeter
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ contract Greeter {
// This is less resource intensive than writing to storage.
address cdmAddr = address(0);

// Mainnet
if (block.chainid == 1)
cdmAddr = 0x25ace71c97B33Cc4729CF772ae268934F7ab5fA1;

// Kovan
if (block.chainid == 42)
cdmAddr = 0x4361d0F75A0186C05f971c566dC6bEa5957483fD;

// L2
if (block.chainid == 10 || block.chainid == 69)
// Goerli
if (block.chainid == 5)
cdmAddr = 0x5086d1eEF304eb5284A0f6720f79403b4e9bE294;

// L2 (same address on every network)
if (block.chainid == 10 || block.chainid == 69 || block.chainid == 420)
cdmAddr = 0x4200000000000000000000000000000000000007;

// If this isn't a cross domain message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
module.exports = {
solidity: "0.8.4",
networks: {
"optimistic-kovan": {
url: 'https://kovan.optimism.io',
"optimistic-goerli": {
url: process.env.OPTI_GOERLI_URL,
accounts: { mnemonic: process.env.MNEMONIC }
},
"kovan": {
url: process.env.KOVAN_URL,
"goerli": {
url: process.env.GOERLI_URL,
accounts: { mnemonic: process.env.MNEMONIC }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe("Greeter", function () {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();
console.log(`Testing with greeter at ${greeter.address}`)

expect(await greeter.greet()).to.equal("Hello, world!");

Expand Down
93 changes: 91 additions & 2 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ In [dapp tools](https://github.com/dapphub/dapptools) use this command:
- For the Optimistic Kovan test network:

```sh
export ETH_RPC_URL=https://kovan.optimism.io:8545
export ETH_RPC_URL=https://kovan.optimism.io
```

- For the Optimism production network:

```sh
export ETH_RPC_URL=https://mainnet.optimism.io:8545
export ETH_RPC_URL=https://mainnet.optimism.io
```

### Greeter interaction
Expand Down Expand Up @@ -278,6 +278,95 @@ To interact with the blockchain you use the command line.
seth call $GREETER "greet()" | seth --to-ascii
```


## Foundry

### Connecting to Optimism

In [Foundry](https://book.getfoundry.sh) use this command:

- For a local development node:

```sh
export ETH_RPC_URL=https://localhost:8545
```

- For the Optimistic Kovan test network:

```sh
export ETH_RPC_URL=https://kovan.optimism.io
```

- For the Optimism production network:

```sh
export ETH_RPC_URL=https://mainnet.optimism.io
```

### Greeter interaction

Dapptools does not give us a JavaScript console.
To interact with the blockchain you use the command line.

1. Set the RPC URL and the contract address.

```sh
export ETH_RPC_URL=https://kovan.optimism.io
export GREETER=0xE0A5fe4Fd70B6ea4217122e85d213D70766d6c2c
```

1. Call `greet()`. Notice that the response is provided in hex.

```sh
cast call $GREETER "greet()"
```

1. Call `greet()` again, and this time translate to ASCII

```sh
cast call $GREETER "greet()" | cast --to-ascii
```

1. Put your mnemonic in a file `mnem.delme` and send a transaction.

```sh
cast send --mnemonic-path mnem.delme $GREETER "setGreeting(string)" '"hello"'
```

1. Test that the greeting has changed:

```sh
cast call $GREETER "greet()" | cast --to-ascii
```


### Using the Optimism contract library

This library is provided as an [npm package](https://www.npmjs.com/package/@eth-optimism/contracts), which is different from what forge expects.
Here is how you can import it without importing the entire Optimism monorepo:

1. Install the tools: [Node.js](https://nodejs.org/en/download/) and [yarn](https://classic.yarnpkg.com/lang/en/).

1. Install the `@eth-optimism/contracts` library under `.../lib`.

```sh
cd lib
yarn add @eth-optimism/contracts
```

1. If you are using `git`, add `node_modules` to [`.gitignore`](https://git-scm.com/docs/gitignore).

1. The remapping that `forge` deduces is not the same as what you would have with hardhat.
To ensure source code compatibility, create a file (in the application's root directory) called `remappings.txt` with this content:

```
@eth-optimism/=lib/node_modules/@eth-optimism/
```

You can now run `forge build` with contracts that use the Optimism contract library.
You can see this structure in the `foundry` directory of this tutorial.


## Waffle

Starting from [Waffle](https://github.com/TrueFiEng/Waffle) v4.x.x you can use Waffle chai matchers to test your smart contracts directly on an Optimism node.
Expand Down
6 changes: 6 additions & 0 deletions getting-started/foundry/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[default]
src = 'src'
out = 'out'
libs = ['lib']

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
1 change: 1 addition & 0 deletions getting-started/foundry/lib/forge-std
Submodule forge-std added at 6f3b43
5 changes: 5 additions & 0 deletions getting-started/foundry/lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@eth-optimism/contracts": "^0.5.29"
}
}
Loading