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

+8-10
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

+6-2
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

+7-3
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

+2-2
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

+3-3
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

+2-10
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

+21-17
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

+10
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

+23
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

+1-12
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
}

packages/contract-deposit/.env-sample

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
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. You can use any Arbitrum chain.
10-
11-
L2RPC="https://sepolia-rollup.arbitrum.io/rpc"
12-
13-
# Ethereum RPC; i.e., for Sepolia https://sepolia.infura.io/v3/<your infura key>
4+
# Your private key
5+
PRIVATE_KEY="0x your key here"
146

15-
L1RPC=""
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"
1610

17-
# The address that you will transfer the funds from your l2 alias to
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>"
1814

15+
# The address that you will transfer the funds from your address alias on the child chain to
1916
TransferTo=

packages/contract-deposit/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
It will deposit funds to l2 via a l1 contract, and because the inbox contract will alias the sender address if it is a contract,
66
this tutorial shows how to control the alias address on l2 via its l1 contract address.
77

8-
This tutorial demonstrates depositing funds to L2 using an L1 contract. Since the Inbox contract changes the sender address if it's a contract [(a.k.a address aliasing)](https://docs.arbitrum.io/how-arbitrum-works/arbos/l1-l2-messaging#address-aliasing), it explains how to manage the new L2 address using the L1 contract address. It's a basic example of how an L1 contract controls its L2 alias and transfers its alias funds to another address. For practical use, we recommend our [funds recovery tool]((https://github.com/OffchainLabs/arbitrum-funds-recovery-tool)).
8+
This tutorial demonstrates depositing funds to L2 using an L1 contract. Since the Inbox contract changes the sender address if it's a contract [(a.k.a address aliasing)](https://docs.arbitrum.io/how-arbitrum-works/arbos/l1-l2-messaging#address-aliasing), it explains how to manage the new L2 address using the L1 contract address. It's a basic example of how an L1 contract controls its L2 alias and transfers its alias funds to another address. For practical use, we recommend our [funds recovery tool](<(https://github.com/OffchainLabs/arbitrum-funds-recovery-tool)>).
99

1010
The script and contracts demonstrate how to interact with Arbitrum's core bridge contracts to create these retryable messages, how to calculate and forward appropriate fees from L1 to L2, and how to use Arbitrum's L1-to-L2 message [address aliasing](https://developer.offchainlabs.com/docs/l1_l2_messages#address-aliasing).
1111

packages/contract-deposit/contracts/EthDeposit.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
pragma solidity >=0.6.11;
2+
pragma solidity ^0.8.0;
33

44
import "@arbitrum/nitro-contracts/src/bridge/Inbox.sol";
55

@@ -13,14 +13,14 @@ contract EthDeposit {
1313
inbox = IInbox(_inbox);
1414
}
1515

16-
function depositToL2() public payable returns (uint256) {
16+
function depositToChildChain() public payable returns (uint256) {
1717
uint256 ticketID = inbox.depositEth{ value: msg.value }();
1818

1919
emit EthDeposited(ticketID);
2020
return ticketID;
2121
}
2222

23-
function moveFundsFromL2AliasToAnotherAddress(
23+
function moveFundsFromChildChainAliasToAnotherAddress(
2424
address to,
2525
uint256 l2callvalue,
2626
uint256 maxSubmissionCost,
@@ -29,8 +29,8 @@ contract EthDeposit {
2929
) public payable returns (uint256) {
3030
/**
3131
* We are using unsafeCreateRetryableTicket because the safe one will check if
32-
* the msg.value can be used to pay for the l2 callvalue while we will use l2's
33-
* balance to pay for the l2 callvalue rather than l1 msg.value.
32+
* the parent chain's msg.value can be used to pay for the child chain's callvalue, while in this case
33+
* we'll use child chain's balance to pay for the callvalue rather than parent chain's msg.value
3434
*/
3535
uint256 ticketID = inbox.unsafeCreateRetryableTicket{ value: msg.value }(
3636
to,

packages/contract-deposit/package.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@
66
"build": "hardhat compile",
77
"start": "hardhat run scripts/exec.js"
88
},
9-
"devDependencies": {
10-
"@nomiclabs/hardhat-ethers": "^2.0.2",
11-
"ethers": "^5.1.2",
12-
"hardhat": "^2.2.0"
13-
},
149
"dependencies": {
15-
"@arbitrum/sdk": "^v3.1.9",
16-
"@arbitrum/nitro-contracts": "v1.0.2",
17-
"dotenv": "^8.2.0"
10+
"@arbitrum/sdk": "^4.0.1",
11+
"@arbitrum/nitro-contracts": "2.1.0"
1812
}
1913
}

0 commit comments

Comments
 (0)