Skip to content

Commit 10d218c

Browse files
authored
Merge pull request #124 from OffchainLabs/update-to-arb-sdk-4
Update tutorials to Arbitrum SDK v4 and Solidity 0.8
2 parents dc14c7a + ad56bc9 commit 10d218c

124 files changed

Lines changed: 2834 additions & 7968 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env-sample

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# This is a sample .env file for use in local development.
2-
32
# Duplicate this file as .env here
43

5-
# Your Private key
6-
7-
DEVNET_PRIVKEY="0x your key here"
8-
9-
# Hosted Aggregator Node (JSON-RPC Endpoint). This is Arbitrum Sepolia Testnet, can use any Arbitrum chain
10-
11-
L2RPC="https://sepolia-rollup.arbitrum.io/rpc"
4+
# Your private key
5+
PRIVATE_KEY="0x your key here"
126

13-
# Ethereum RPC; i.e., for Sepolia https://sepolia.infura.io/v3/<your infura key>
7+
# The main chain's RPC
8+
# (this can be an Arbitrum network, or your Orbit chain)
9+
CHAIN_RPC="https://sepolia-rollup.arbitrum.io/rpc"
1410

15-
L1RPC=""
11+
# The parent chain's RPC
12+
# (this can be Ethereum, or the chain your Orbit chain settles to)
13+
PARENT_CHAIN_RPC="https://sepolia.infura.io/v3/<your infura key>"

README.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Arbitrum Tutorials
22

3-
This monorepo will help you get started with building on Arbitrum. It provides various simple demos showing and explaining how to interact with Arbitrum — deploying and using contracts directly on L2, moving Ether and tokens betweens L1 and L2, and more.
3+
This monorepo will help you get started with building on Arbitrum chains. It provides various simple demos showing and explaining how to interact with Arbitrum chains (including Orbit chains) — deploying and using contracts directly on Arbitrum, moving Ether and tokens betweens the parent and child chains, and more.
44

55
We show how you can use broadly supported Ethereum ecosystem tooling (Hardhat, Ethers-js, etc.) as well as our special [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk) for convenience.
66

@@ -16,30 +16,43 @@ yarn install
1616

1717
#### :white_check_mark: Basics
1818

19-
- 🐹 [Pet Shop DApp](./packages/demo-dapp-pet-shop/) (L2 only)
20-
- 🗳 [Election DApp](./packages/demo-dapp-election/) (L2 only)
19+
- 🐹 [Pet Shop DApp](./packages/demo-dapp-pet-shop/)
20+
- 🗳 [Election DApp](./packages/demo-dapp-election/)
2121

22-
#### :white_check_mark: Moving Stuff around
22+
#### :white_check_mark: Moving stuff around
2323

24-
- ⤴️ 🔹 [Deposit Ether](./packages/eth-deposit/)
25-
- ⤵️ 🔹 [Withdraw Ether](./packages/eth-withdraw/)
26-
- ⤴️ 💸 [Deposit Token](./packages/token-deposit/)
24+
- ⤴️ 🔹 [Deposit Ether or native token](./packages/eth-deposit/)
25+
- ⤴️ 🔹 [Deposit Ether or native token to a different address](./packages/eth-deposit-to-different-address/)
26+
- ⤵️ 🔹 [Withdraw Ether or native token](./packages/eth-withdraw/)
27+
- ⤴️ 💸 [Deposit token](./packages/token-deposit/)
2728
- ⤵️ 💸 [Withdraw token](./packages/token-withdraw/)
28-
- ⤴️ 🔹 [L2 Alias Control and Fund Transfer Guide](./packages/contract-deposit/)
29+
- ⤴️ 🔹 [Contract alias control in the child chain, and fund-transfer guide](./packages/contract-deposit/)
2930

3031
#### :white_check_mark: General interop
3132

32-
- 🤝 [Greeter](./packages/greeter/) (L1 to L2)
33-
- 📤 [Outbox](./packages/outbox-execute/) (L2 to L1)
34-
-[L1 Confirmation Checker](./packages/l1-confirmation-checker/)
35-
-[L2 block verification in assertion](./packages/l2-block-verification-in-assertion/)
33+
- 🤝 [Greeter](./packages/greeter/) (parent to child messages)
34+
- 📤 [Outbox tutorial: execute a child-to-parent message](./packages/outbox-execute/) (child to parent messages)
35+
-[Parent chain confirmation checker](./packages/parent-chain-confirmation-checker/)
36+
-[Block verification in parent chain's assertion](./packages/block-verification-in-parent-chain-assertion/)
3637

37-
#### :white_check_mark: Advanced Features
38+
#### :white_check_mark: Advanced features
3839

39-
- ®️ [Arb Address Table](./packages/address-table/)
40-
- 🌉 [Bridging Custom Token](./packages/custom-token-bridging/)
41-
- ✈️ [Delayed inbox message(l2MSG)](./packages/delayedInbox-l2msg/)
42-
- 🎁 [Redeem Retryable Ticket](./packages/redeem-failed-retryable/)
40+
- ®️ [ArbAddress table](./packages/address-table/)
41+
- 🌉 [Bridging a custom token through the generic-custom gateway](./packages/custom-token-bridging/)
42+
- 🌉 [Bridging a custom token through a custom gateway](./packages/custom-gateway-bridging/)
43+
- ✈️ [Send a signed transaction from the parent chain](./packages/delayedInbox-l2msg/)
44+
- 🎁 [Redeem pending retryable ticket](./packages/redeem-pending-retryable/)
45+
- 🧮 [Gas estimation](./packages/gas-estimation/)
4346
- 🌀 [Deposit Ether or Tokens from L1 to L3](./packages/l1-l3-teleport/)
4447

48+
## How to run the tutorials against a custom network
49+
50+
As mentioned above, these tutorials use the [Arbitrum SDK](https://github.com/OffchainLabs/arbitrum-sdk), which loads the regular Arbitrum chains by default (Arbitrum One, Arbitrum Nova and Arbitrum Sepolia). You can use these tutorials against any other Arbitrum chain (including Orbit chains), by loading it to the Arbitrum SDK.
51+
52+
To do that, fill the information of your chain in the [`customNetwork.json`](./customNetwork.json) file, which is automatically loaded in all tutorials.
53+
54+
To obtain the information of a specific chain, you can use the method [`prepareArbitrumNetwork`](https://github.com/OffchainLabs/arbitrum-orbit-sdk/blob/main/src/utils/registerNewNetwork.ts#L18) of the Orbit SDK.
55+
56+
You can also register multiple chains if you need to (for example, for the `l1-l3-teleport` tutorial). In that case, create an array of chain information objects in the `customNetwork.json` file.
57+
4558
<p align="center"><img src="assets/logo.svg" width="300"></p>

customNetwork.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"chainID": 412346,
3+
"confirmPeriodBlocks": 20,
4+
"ethBridge": {
5+
"bridge": "0x5eCF728ffC5C5E802091875f96281B5aeECf6C49",
6+
"inbox": "0x9f8c1c641336A371031499e3c362e40d58d0f254",
7+
"outbox": "0x50143333b44Ea46255BEb67255C9Afd35551072F",
8+
"rollup": "0x7d98BA231d29D5C202981542C0291718A7358c63",
9+
"sequencerInbox": "0x18d19C5d3E685f5be5b9C86E097f0E439285D216"
10+
},
11+
"explorerUrl": "",
12+
"isArbitrum": true,
13+
"isCustom": true,
14+
"name": "ArbLocal",
15+
"partnerChainID": 1337,
16+
"retryableLifetimeSeconds": 604800,
17+
"nitroGenesisBlock": 0,
18+
"nitroGenesisL1Block": 0,
19+
"depositTimeout": 900000,
20+
"tokenBridge": {
21+
"parentGatewayRouter": "0x093AAa96CD4387A68FC0e24C60140938Dc812549",
22+
"childGatewayRouter": "0x32656396981868E925280FB772b3f806892cf4bF",
23+
"parentErc20Gateway": "0x00D9fE1a2B67B8151aEdE8855c95E58D73FB4245",
24+
"childErc20Gateway": "0x7424e3DAAAAcd867c85ceB75c1E00119F2ee5eb7",
25+
"parentCustomGateway": "0x8407E6180dC009D20D26D4BABB4790C1d4E6D2aA",
26+
"childCustomGateway": "0x0B35cfE62314C3852A0942b5830c728353BD654F",
27+
"parentWethGateway": "0xB8F48Ba39fCfB44d70F6008fe1bf4F3E744044AF",
28+
"childWethGateway": "0x67aE8014BD1A0c1Ed747715d22b3b3a188aC324B",
29+
"parentWeth": "0x7E32b54800705876d3b5cFbc7d9c226a211F7C1a",
30+
"childWeth": "0xA1abD387192e3bb4e84D3109181F9f005aBaF5CA",
31+
"parentProxyAdmin": "0x2A1f38c9097e7883570e0b02BFBE6869Cc25d8a3",
32+
"childProxyAdmin": "0x9F95547ABB0FfC92b4E37b3124d1e8613d5aB74A",
33+
"parentMultiCall": "0x49117fC32930E324F2E9A7BeA588FFb26008b8eC",
34+
"childMultiCall": "0x6B1E93aE298B64e8f5b9f43B65Dd8F1eaA6DD4c3"
35+
},
36+
"chainId": 412346,
37+
"parentChainId": 1337
38+
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "Apache-2.0",
77
"private": "true",
88
"engines": {
9-
"node": ">= 8.0.0 < 17.0.0",
9+
"node": ">= 8.0.0",
1010
"npm": "^6.0.0",
1111
"yarn": "^1.0.0"
1212
},
@@ -23,7 +23,11 @@
2323
"prettier-plugin-solidity": "^1.0.0-beta.17"
2424
},
2525
"dependencies": {
26-
"@arbitrum/sdk": "^3.4.1"
26+
"@arbitrum/sdk": "^4.0.1",
27+
"@nomiclabs/hardhat-ethers": "^2.0.2",
28+
"ethers": "^5.4.1",
29+
"hardhat": "^2.2.0",
30+
"dotenv": "^16.4.5"
2731
},
2832
"workspaces": {
2933
"packages": [

packages/address-table/.env-sample

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
DEVNET_PRIVKEY="0x your key here"
1+
# This is a sample .env file for use in local development.
2+
# Duplicate this file as .env here
23

3-
# This is Arbitrum Sepolia Testnet, can use any Arbitrum chain
4-
L2RPC="https://sepolia-rollup.arbitrum.io/rpc"
4+
# Your private key
5+
PRIVATE_KEY="0x your key here"
56

7+
# The main chain's RPC
8+
# (this can be an Arbitrum network, or your Orbit chain)
9+
CHAIN_RPC="https://sepolia-rollup.arbitrum.io/rpc"

packages/address-table/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Address Table Demo
1+
# Address table demo
22

3-
The Address table is a precompiled contract on Arbitrum for registering addresses which are then retrievable by an integer index; this saves gas by minimizing precious calldata required to input an address as a parameter.
3+
The Address table is a precompiled contract on Arbitrum chains for registering addresses which are then retrievable by an integer index; this saves gas by minimizing precious calldata required to input an address as a parameter.
44

55
This demo shows a simple contract with affordances to retrieve an address from a contract by its index in the address table, and a client-side script to pre-register the given address (if necessary).
66

@@ -12,19 +12,21 @@ See `exec.js` for inline comments / explanation.
1212
yarn run exec
1313
```
1414

15-
## Config Environment Variables
15+
## Set environment variables
1616

1717
Set the values shown in `.env-sample` as environmental variables. To copy it into a `.env` file:
1818

1919
```bash
2020
cp .env-sample .env
2121
```
2222

23-
(you'll still need to edit some variables, i.e., `DEVNET_PRIVKEY`)
23+
You'll still need to edit some variables, i.e., `PRIVATE_KEY` and `CHAIN_RPC`.
24+
25+
Note that you can also set the environment variables in an `.env` file in the root of the monorepo, which will be available in all tutorials.
2426

2527
### More info
2628

27-
See our [developer documentation for more info](https://developer.offchainlabs.com/docs/special_features).
29+
See our [developer documentation for more info](https://docs.arbitrum.io/).
2830

2931
<p align="left">
3032
<img width="350" height="150" src= "../../assets/logo.svg" />

packages/address-table/contracts/ArbitrumVIP.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//SPDX-License-Identifier: Unlicense
2-
pragma solidity ^0.7.2;
2+
pragma solidity ^0.8.0;
33

44
import "@arbitrum/nitro-contracts/src/precompiles/ArbAddressTable.sol";
55
import "hardhat/console.sol";
@@ -10,9 +10,9 @@ contract ArbitrumVIP {
1010

1111
ArbAddressTable arbAddressTable;
1212

13-
constructor() public {
13+
constructor() {
1414
// connect to precomiled address table contract
15-
arbAddressTable = ArbAddressTable(102);
15+
arbAddressTable = ArbAddressTable(address(102));
1616
}
1717

1818
function addVIPPoints(uint256 addressIndex) external {

packages/address-table/package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
"license": "Apache-2.0",
44
"version": "1.0.0",
55
"scripts": {
6-
"exec": "hardhat run scripts/exec.js --network l2"
7-
},
8-
"devDependencies": {
9-
"@nomiclabs/hardhat-ethers": "^2.0.2",
10-
"@nomiclabs/hardhat-waffle": "^2.0.1",
11-
"chai": "^4.3.4",
12-
"ethereum-waffle": "^3.4.0",
13-
"ethers": "^5.4.2",
14-
"hardhat": "^2.5.0"
6+
"exec": "hardhat run scripts/exec.js"
157
},
168
"dependencies": {
17-
"@arbitrum/sdk": "^v3.1.9"
9+
"@arbitrum/sdk": "^4.0.1"
1810
}
1911
}

packages/address-table/scripts/exec.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1+
const { providers, Wallet } = require('ethers')
12
const hre = require('hardhat')
23
const {
34
ArbAddressTable__factory,
45
} = require('@arbitrum/sdk/dist/lib/abi/factories/ArbAddressTable__factory')
5-
const { addDefaultLocalNetwork } = require('@arbitrum/sdk')
66
const { arbLog, requireEnvVariables } = require('arb-shared-dependencies')
7-
requireEnvVariables(['DEVNET_PRIVKEY', 'L2RPC'])
7+
const {
8+
ARB_ADDRESS_TABLE_ADDRESS,
9+
} = require('@arbitrum/sdk/dist/lib/dataEntities/constants')
810
require('dotenv').config()
11+
requireEnvVariables(['PRIVATE_KEY', 'CHAIN_RPC'])
12+
13+
/**
14+
* Set up: instantiate wallets connected to providers
15+
*/
16+
const walletPrivateKey = process.env.PRIVATE_KEY
17+
const provider = new providers.JsonRpcProvider(process.env.CHAIN_RPC)
18+
const wallet = new Wallet(walletPrivateKey, provider)
919

1020
async function main() {
1121
await arbLog('Using the Address Table')
1222

1323
/**
14-
* Add the default local network configuration to the SDK
15-
* to allow this script to run on a local node
24+
* Deploy ArbitrumVIP contract
1625
*/
17-
addDefaultLocalNetwork()
18-
19-
/**
20-
* Deploy ArbitrumVIP contract to L2
21-
*/
22-
const ArbitrumVIP = await hre.ethers.getContractFactory('ArbitrumVIP')
23-
const arbitrumVIP = await ArbitrumVIP.deploy()
24-
26+
const ArbitrumVIPContract = await (
27+
await hre.ethers.getContractFactory('ArbitrumVIP')
28+
).connect(wallet)
29+
console.log('Deploying ArbitrumVIP contract...')
30+
const arbitrumVIP = await ArbitrumVIPContract.deploy()
2531
await arbitrumVIP.deployed()
26-
2732
console.log('ArbitrumVIP deployed to:', arbitrumVIP.address)
2833

29-
const signers = await hre.ethers.getSigners()
30-
const myAddress = signers[0].address
34+
const myAddress = wallet.address
3135

3236
/**
3337
* Connect to the Arbitrum Address table pre-compile contract
3438
*/
3539
const arbAddressTable = ArbAddressTable__factory.connect(
36-
'0x0000000000000000000000000000000000000066',
37-
signers[0]
40+
ARB_ADDRESS_TABLE_ADDRESS,
41+
wallet
3842
)
3943

4044
//**

packages/arb-shared-dependencies/hardhat.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,15 @@ module.exports = {
4646
? [process.env['DEVNET_PRIVKEY']]
4747
: [],
4848
},
49+
parent_chain: {
50+
gas: 2100000,
51+
gasLimit: 0,
52+
url: process.env['PARENT_CHAIN_RPC'] || '',
53+
accounts: process.env['PRIVATE_KEY'] ? [process.env['PRIVATE_KEY']] : [],
54+
},
55+
chain: {
56+
url: process.env['CHAIN_RPC'] || '',
57+
accounts: process.env['PRIVATE_KEY'] ? [process.env['PRIVATE_KEY']] : [],
58+
},
4959
},
5060
}

0 commit comments

Comments
 (0)