Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tutorials to Arbitrum SDK v4 and Solidity 0.8 #124

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
48b81dd
Update tutorials to Arbitrum SDK v4
TucksonDev Oct 25, 2024
05e6b13
Update tutorials to ArbSDK v4 (1)
TucksonDev Oct 25, 2024
b1aacf2
Update tutorials to ArbSDK v4 (2)
TucksonDev Nov 1, 2024
60b5097
Add lock file
TucksonDev Nov 1, 2024
9087d0b
Rename custom network file
TucksonDev Nov 1, 2024
bd034e5
Merge branch 'update-to-arb-sdk-4' into update-tutorials-1
TucksonDev Nov 1, 2024
98e12df
Fix contract-deposit and rename function to add custom network
TucksonDev Nov 1, 2024
0e354aa
Update README files
TucksonDev Nov 1, 2024
0266273
Merge branch 'update-tutorials-1' into update-tutorials-2
TucksonDev Nov 1, 2024
12ffda0
Update READMEs
TucksonDev Nov 1, 2024
53be371
Update READMEs
TucksonDev Nov 1, 2024
6944861
Merge pull request #125 from OffchainLabs/update-tutorials-1
TucksonDev Nov 4, 2024
bcc11fd
Update tutorials 3
TucksonDev Nov 4, 2024
a0028fe
Smol adjustments to README files and comments
TucksonDev Nov 6, 2024
250f5fc
Mention native gas tokens for Orbit chains
TucksonDev Nov 6, 2024
99c0af9
Merge pull request #127 from OffchainLabs/update-tutorials-3
TucksonDev Nov 6, 2024
f23bf1e
Merge branch 'update-to-arb-sdk-4' into update-tutorials-2
TucksonDev Nov 11, 2024
b0eadb0
Fix yarn.lock
TucksonDev Nov 11, 2024
c41caa7
Update tutorials to ArbSDK v4 (4)
TucksonDev Nov 11, 2024
45112c7
Merge branch 'master' into update-to-arb-sdk-4
TucksonDev Nov 26, 2024
fc2d2df
Merge pull request #126 from OffchainLabs/update-tutorials-2
TucksonDev Nov 26, 2024
8655118
Renamed l1-confirmation-checker package
TucksonDev Nov 26, 2024
3f140c7
Merge pull request #128 from OffchainLabs/update-tutorials-4
TucksonDev Nov 26, 2024
27e71fd
Fix extra period
TucksonDev Nov 26, 2024
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
18 changes: 8 additions & 10 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# This is a sample .env file for use in local development.

# Duplicate this file as .env here

# Your Private key

DEVNET_PRIVKEY="0x your key here"

# Hosted Aggregator Node (JSON-RPC Endpoint). This is Arbitrum Sepolia Testnet, can use any Arbitrum chain

L2RPC="https://sepolia-rollup.arbitrum.io/rpc"
# Your private key
PRIVATE_KEY="0x your key here"

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

L1RPC=""
# The parent chain's RPC
# (this can be Ethereum, or the chain your Orbit chain settles to)
PARENT_CHAIN_RPC="https://sepolia.infura.io/v3/<your infura key>"
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Arbitrum Tutorials

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.
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.

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.

Expand All @@ -16,30 +16,39 @@ yarn install

#### :white_check_mark: Basics

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

#### :white_check_mark: Moving Stuff around
#### :white_check_mark: Moving stuff around

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

#### :white_check_mark: General interop

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

#### :white_check_mark: Advanced Features
#### :white_check_mark: Advanced features

- ®️ [Arb Address Table](./packages/address-table/)
- 🌉 [Bridging Custom Token](./packages/custom-token-bridging/)
- ✈️ [Delayed inbox message(l2MSG)](./packages/delayedInbox-l2msg/)
- ✈️ [Send a signed transaction from the parent chain](./packages/delayedInbox-l2msg/)
- 🎁 [Redeem Retryable Ticket](./packages/redeem-failed-retryable/)
- 🌀 [Deposit Ether or Tokens from L1 to L3](./packages/l1-l3-teleport/)

## How to run the tutorials against a custom network

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.

To do that, fill the information of your chain in the [`customNetwork.json`](./customNetwork.json) file., which is automatically loaded in all tutorials.
TucksonDev marked this conversation as resolved.
Show resolved Hide resolved

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.

<p align="center"><img src="assets/logo.svg" width="300"></p>
38 changes: 38 additions & 0 deletions customNetwork.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"chainID": 412346,
"confirmPeriodBlocks": 20,
"ethBridge": {
"bridge": "0x5eCF728ffC5C5E802091875f96281B5aeECf6C49",
"inbox": "0x9f8c1c641336A371031499e3c362e40d58d0f254",
"outbox": "0x50143333b44Ea46255BEb67255C9Afd35551072F",
"rollup": "0x837Fadd53667eFCE195D5B75063aaB277f7d712C",
"sequencerInbox": "0x18d19C5d3E685f5be5b9C86E097f0E439285D216"
},
"explorerUrl": "",
"isArbitrum": true,
"isCustom": true,
"name": "ArbLocal",
"partnerChainID": 1337,
"retryableLifetimeSeconds": 604800,
"nitroGenesisBlock": 0,
"nitroGenesisL1Block": 0,
"depositTimeout": 900000,
"tokenBridge": {
"parentGatewayRouter": "0x093AAa96CD4387A68FC0e24C60140938Dc812549",
"childGatewayRouter": "0x32656396981868E925280FB772b3f806892cf4bF",
"parentErc20Gateway": "0x00D9fE1a2B67B8151aEdE8855c95E58D73FB4245",
"childErc20Gateway": "0x7424e3DAAAAcd867c85ceB75c1E00119F2ee5eb7",
"parentCustomGateway": "0x8407E6180dC009D20D26D4BABB4790C1d4E6D2aA",
"childCustomGateway": "0x0B35cfE62314C3852A0942b5830c728353BD654F",
"parentWethGateway": "0xB8F48Ba39fCfB44d70F6008fe1bf4F3E744044AF",
"childWethGateway": "0x67aE8014BD1A0c1Ed747715d22b3b3a188aC324B",
"parentWeth": "0x7E32b54800705876d3b5cFbc7d9c226a211F7C1a",
"childWeth": "0xA1abD387192e3bb4e84D3109181F9f005aBaF5CA",
"parentProxyAdmin": "0x2A1f38c9097e7883570e0b02BFBE6869Cc25d8a3",
"childProxyAdmin": "0x9F95547ABB0FfC92b4E37b3124d1e8613d5aB74A",
"parentMultiCall": "0x49117fC32930E324F2E9A7BeA588FFb26008b8eC",
"childMultiCall": "0x6B1E93aE298B64e8f5b9f43B65Dd8F1eaA6DD4c3"
},
"chainId": 412346,
"parentChainId": 1337
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Apache-2.0",
"private": "true",
"engines": {
"node": ">= 8.0.0 < 17.0.0",
"node": ">= 8.0.0",
"npm": "^6.0.0",
"yarn": "^1.0.0"
},
Expand All @@ -23,7 +23,11 @@
"prettier-plugin-solidity": "^1.0.0-beta.17"
},
"dependencies": {
"@arbitrum/sdk": "^3.4.1"
"@arbitrum/sdk": "^4.0.1",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"ethers": "^5.4.1",
"hardhat": "^2.2.0",
"dotenv": "^16.4.5"
},
"workspaces": {
"packages": [
Expand Down
10 changes: 7 additions & 3 deletions packages/address-table/.env-sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
DEVNET_PRIVKEY="0x your key here"
# This is a sample .env file for use in local development.
# Duplicate this file as .env here

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

# The main chain's RPC
# (this can be an Arbitrum network, or your Orbit chain)
CHAIN_RPC="https://sepolia-rollup.arbitrum.io/rpc"
12 changes: 7 additions & 5 deletions packages/address-table/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Address Table Demo
# Address table demo

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.
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.

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).

Expand All @@ -12,19 +12,21 @@ See `exec.js` for inline comments / explanation.
yarn run exec
```

## Config Environment Variables
## Set environment variables

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

```bash
cp .env-sample .env
```

(you'll still need to edit some variables, i.e., `DEVNET_PRIVKEY`)
You'll still need to edit some variables, i.e., `PRIVATE_KEY` and `CHAIN_RPC`.

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.

### More info

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

<p align="left">
<img width="350" height="150" src= "../../assets/logo.svg" />
Expand Down
6 changes: 3 additions & 3 deletions packages/address-table/contracts/ArbitrumVIP.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.2;
pragma solidity ^0.8.0;

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

ArbAddressTable arbAddressTable;

constructor() public {
constructor() {
// connect to precomiled address table contract
arbAddressTable = ArbAddressTable(102);
arbAddressTable = ArbAddressTable(address(102));
}

function addVIPPoints(uint256 addressIndex) external {
Expand Down
12 changes: 2 additions & 10 deletions packages/address-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
"license": "Apache-2.0",
"version": "1.0.0",
"scripts": {
"exec": "hardhat run scripts/exec.js --network l2"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.2",
"hardhat": "^2.5.0"
"exec": "hardhat run scripts/exec.js"
},
"dependencies": {
"@arbitrum/sdk": "^v3.1.9"
"@arbitrum/sdk": "^4.0.1"
}
}
38 changes: 21 additions & 17 deletions packages/address-table/scripts/exec.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
const { providers, Wallet } = require('ethers')
const hre = require('hardhat')
const {
ArbAddressTable__factory,
} = require('@arbitrum/sdk/dist/lib/abi/factories/ArbAddressTable__factory')
const { addDefaultLocalNetwork } = require('@arbitrum/sdk')
const { arbLog, requireEnvVariables } = require('arb-shared-dependencies')
requireEnvVariables(['DEVNET_PRIVKEY', 'L2RPC'])
const {
ARB_ADDRESS_TABLE_ADDRESS,
} = require('@arbitrum/sdk/dist/lib/dataEntities/constants')
requireEnvVariables(['PRIVATE_KEY', 'CHAIN_RPC'])
require('dotenv').config()

/**
* Set up: instantiate wallets connected to providers
*/
const walletPrivateKey = process.env.PRIVATE_KEY
const provider = new providers.JsonRpcProvider(process.env.CHAIN_RPC)
const wallet = new Wallet(walletPrivateKey, provider)

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

/**
* Add the default local network configuration to the SDK
* to allow this script to run on a local node
* Deploy ArbitrumVIP contract
*/
addDefaultLocalNetwork()

/**
* Deploy ArbitrumVIP contract to L2
*/
const ArbitrumVIP = await hre.ethers.getContractFactory('ArbitrumVIP')
const arbitrumVIP = await ArbitrumVIP.deploy()

const ArbitrumVIPContract = await (
await hre.ethers.getContractFactory('ArbitrumVIP')
).connect(wallet)
console.log('Deploying ArbitrumVIP contract...')
const arbitrumVIP = await ArbitrumVIPContract.deploy()
await arbitrumVIP.deployed()

console.log('ArbitrumVIP deployed to:', arbitrumVIP.address)

const signers = await hre.ethers.getSigners()
const myAddress = signers[0].address
const myAddress = wallet.address

/**
* Connect to the Arbitrum Address table pre-compile contract
*/
const arbAddressTable = ArbAddressTable__factory.connect(
'0x0000000000000000000000000000000000000066',
signers[0]
ARB_ADDRESS_TABLE_ADDRESS,
wallet
)

//**
Expand Down
10 changes: 10 additions & 0 deletions packages/arb-shared-dependencies/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ module.exports = {
? [process.env['DEVNET_PRIVKEY']]
: [],
},
parent_chain: {
gas: 2100000,
gasLimit: 0,
url: process.env['PARENT_CHAIN_RPC'] || '',
accounts: process.env['PRIVATE_KEY'] ? [process.env['PRIVATE_KEY']] : [],
},
chain: {
url: process.env['CHAIN_RPC'] || '',
accounts: process.env['PRIVATE_KEY'] ? [process.env['PRIVATE_KEY']] : [],
},
},
}
23 changes: 23 additions & 0 deletions packages/arb-shared-dependencies/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const hardhatConfig = require('./hardhat.config.js')
const path = require('path')
const fs = require('fs')
const { registerCustomArbitrumNetwork } = require('@arbitrum/sdk')
require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') })

const wait = (ms = 0) => {
Expand Down Expand Up @@ -49,9 +51,30 @@ const requireEnvVariables = envVars => {
}
console.log('Environmental variables properly set 👍')
}

const addCustomNetworkFromFile = () => {
const pathToCustomNetworkFile = path.join(
__dirname,
'..',
'..',
'customNetwork.json'
)
if (!fs.existsSync(pathToCustomNetworkFile)) {
return
}

const customNetworkFileContents = fs.readFileSync(
pathToCustomNetworkFile,
'utf8'
)
const customNetworkInformation = JSON.parse(customNetworkFileContents)
registerCustomArbitrumNetwork(customNetworkInformation)
}

module.exports = {
arbLog,
arbLogTitle,
hardhatConfig,
requireEnvVariables,
addCustomNetworkFromFile,
}
13 changes: 1 addition & 12 deletions packages/arb-shared-dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,5 @@
"scripts": {
"build": "hardhat compile"
},
"main": "index.js",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"eslint": "^7.30.0",
"ethers": "^5.1.2",
"hardhat": "^2.2.0",
"prettier": "^2.3.2"
},
"dependencies": {
"dotenv": "^8.2.0",
"eslint-plugin-prettier": "^3.4.0"
}
"main": "index.js"
}
21 changes: 9 additions & 12 deletions packages/contract-deposit/.env-sample
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# This is a sample .env file for use in local development.

# Duplicate this file as .env here

# Your Private key

DEVNET_PRIVKEY="0x your key here"

# Hosted aggregator node (JSON-RPC endpoint). This is Arbitrum Sepolia Testnet. You can use any Arbitrum chain.

L2RPC="https://sepolia-rollup.arbitrum.io/rpc"

# Ethereum RPC; i.e., for Sepolia https://sepolia.infura.io/v3/<your infura key>
# Your private key
PRIVATE_KEY="0x your key here"

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

# The address that you will transfer the funds from your l2 alias to
# The parent chain's RPC
# (this can be Ethereum, or the chain your Orbit chain settles to)
PARENT_CHAIN_RPC="https://sepolia.infura.io/v3/<your infura key>"

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