Skip to content

Commit 6944861

Browse files
authored
Merge pull request #125 from OffchainLabs/update-tutorials-1
Update tutorials to ArbSDK v4 (1)
2 parents 9087d0b + 0e354aa commit 6944861

File tree

17 files changed

+378
-5714
lines changed

17 files changed

+378
-5714
lines changed

.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: 16 additions & 8 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,38 @@ 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

2424
- ⤴️ 🔹 [Deposit Ether](./packages/eth-deposit/)
2525
- ⤵️ 🔹 [Withdraw Ether](./packages/eth-withdraw/)
2626
- ⤴️ 💸 [Deposit Token](./packages/token-deposit/)
2727
- ⤵️ 💸 [Withdraw token](./packages/token-withdraw/)
28-
- ⤴️ 🔹 [L2 Alias Control and Fund Transfer Guide](./packages/contract-deposit/)
28+
- ⤴️ 🔹 [Contract alias control in the child chain, and fund-transfer guide](./packages/contract-deposit/)
2929

3030
#### :white_check_mark: General interop
3131

32-
- 🤝 [Greeter](./packages/greeter/) (L1 to L2)
33-
- 📤 [Outbox](./packages/outbox-execute/) (L2 to L1)
32+
- 🤝 [Greeter](./packages/greeter/) (parent to child messages)
33+
- 📤 [Outbox](./packages/outbox-execute/) (child to parent messages)
3434
-[L1 Confirmation Checker](./packages/l1-confirmation-checker/)
3535
-[L2 block verification in assertion](./packages/l2-block-verification-in-assertion/)
3636

37-
#### :white_check_mark: Advanced Features
37+
#### :white_check_mark: Advanced features
3838

3939
- ®️ [Arb Address Table](./packages/address-table/)
4040
- 🌉 [Bridging Custom Token](./packages/custom-token-bridging/)
4141
- ✈️ [Delayed inbox message(l2MSG)](./packages/delayedInbox-l2msg/)
4242
- 🎁 [Redeem Retryable Ticket](./packages/redeem-failed-retryable/)
4343
- 🌀 [Deposit Ether or Tokens from L1 to L3](./packages/l1-l3-teleport/)
4444

45+
## How to run the tutorials against a custom network
46+
47+
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.
48+
49+
To do that, fill the information of your chain in the [`customNetwork.json`](./customNetwork.json) file., which is automatically loaded in all tutorials.
50+
51+
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.
52+
4553
<p align="center"><img src="assets/logo.svg" width="300"></p>

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')
10+
requireEnvVariables(['PRIVATE_KEY', 'CHAIN_RPC'])
811
require('dotenv').config()
912

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)
19+
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
}

packages/arb-shared-dependencies/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const hardhatConfig = require('./hardhat.config.js')
22
const path = require('path')
3+
const fs = require('fs')
4+
const { registerCustomArbitrumNetwork } = require('@arbitrum/sdk')
35
require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') })
46

57
const wait = (ms = 0) => {
@@ -49,9 +51,30 @@ const requireEnvVariables = envVars => {
4951
}
5052
console.log('Environmental variables properly set 👍')
5153
}
54+
55+
const addCustomNetworkFromFile = () => {
56+
const pathToCustomNetworkFile = path.join(
57+
__dirname,
58+
'..',
59+
'..',
60+
'customNetwork.json'
61+
)
62+
if (!fs.existsSync(pathToCustomNetworkFile)) {
63+
return
64+
}
65+
66+
const customNetworkFileContents = fs.readFileSync(
67+
pathToCustomNetworkFile,
68+
'utf8'
69+
)
70+
const customNetworkInformation = JSON.parse(customNetworkFileContents)
71+
registerCustomArbitrumNetwork(customNetworkInformation)
72+
}
73+
5274
module.exports = {
5375
arbLog,
5476
arbLogTitle,
5577
hardhatConfig,
5678
requireEnvVariables,
79+
addCustomNetworkFromFile,
5780
}

0 commit comments

Comments
 (0)