Skip to content

Commit 05e6b13

Browse files
committed
Update tutorials to ArbSDK v4 (1)
1 parent 48b81dd commit 05e6b13

File tree

16 files changed

+345
-5691
lines changed

16 files changed

+345
-5691
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>"

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Set the values shown in `.env-sample` as environmental variables. To copy it int
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`)
2424

2525
### More info
2626

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

2929
<p align="left">
3030
<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 addNetworkFromFile = () => {
56+
const pathToLocalNetworkFile = path.join(
57+
__dirname,
58+
'..',
59+
'..',
60+
'localNetwork.json'
61+
)
62+
if (!fs.existsSync(pathToLocalNetworkFile)) {
63+
return
64+
}
65+
66+
const localNetworksFile = fs.readFileSync(pathToLocalNetworkFile, 'utf8')
67+
const localL2 = JSON.parse(localNetworksFile).l2Network
68+
const localL3 = JSON.parse(localNetworksFile).l3Network
69+
70+
const childChain = localL3 ? localL3 : localL2
71+
registerCustomArbitrumNetwork(childChain)
72+
}
73+
5274
module.exports = {
5375
arbLog,
5476
arbLogTitle,
5577
hardhatConfig,
5678
requireEnvVariables,
79+
addNetworkFromFile,
5780
}

packages/arb-shared-dependencies/package.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,5 @@
55
"scripts": {
66
"build": "hardhat compile"
77
},
8-
"main": "index.js",
9-
"devDependencies": {
10-
"@nomiclabs/hardhat-ethers": "^2.0.2",
11-
"eslint": "^7.30.0",
12-
"ethers": "^5.1.2",
13-
"hardhat": "^2.2.0",
14-
"prettier": "^2.3.2"
15-
},
16-
"dependencies": {
17-
"dotenv": "^8.2.0",
18-
"eslint-plugin-prettier": "^3.4.0"
19-
}
8+
"main": "index.js"
209
}

0 commit comments

Comments
 (0)