• Stars
    star
    226
  • Rank 176,514 (Top 4 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Arbitrum SDK

Typescript library for client-side interactions with Arbitrum. Arbitrum SDK provides common helper functionaliy as well access to the underlying smart contract interfaces.

Below is an overview of the Arbitrum SDK functionality. See the tutorials for further examples of how to use these classes.

Quickstart Recipes

  • Deposit Ether Into Arbitrum
import { getL2Network, EthBridger } from '@arbitrum/sdk'

const l2Network = await getL2Network(
  l2ChainID /** <-- chain id of target Arbitrum chain */
)
const ethBridger = new EthBridger(l2Network)

const ethDepositTxResponse = await ethBridger.deposit({
  amount: utils.parseEther('23'),
  l1Signer: l1Signer /** <-- connected ethers-js Wallet */,
  l2Provider: l2Provider /** <--- ethers-js Provider */,
})

const ethDepositTxReceipt = await ethDepositTxResponse.wait()

/** check ethDepositTxReceipt.status  */
  • Redeem an L1 to L2 Message
import { L1TransactionReceipt, L1ToL2MessageStatus } from '@arbitrum/sdk'

const l1TxnReceipt = new L1TransactionReceipt(
  txnReceipt /** <-- ethers-js TransactionReceipt of an ethereum tx that triggered an L1 to L2 message (say depositting a token via a bridge)  */
)

const l1ToL2Message = (
  await l1TxnReceipt.getL1ToL2Messages(
    l2Signer /** <-- connected ethers-js Wallet */
  )
)[0]

const res = await l1ToL2Message.waitForStatus()

if (res.status === L1ToL2MessageStatus.FUNDS_DEPOSITED_ON_L2) {
  /** Message wasn't auto-redeemed; redeem it now: */
  const response = await l1ToL2Message.redeem()
  const receipt = await response.wait()
} else if (res.status === L1ToL2MessageStatus.REDEEMED) {
  /** Message succesfully redeeemed */
}
  • Check if sequencer has included a transaction in L1 data
import { L2TransactionReceipt } from '@arbitrum/sdk'

const l2TxnReceipt = new L2TransactionReceipt(
  txnReceipt /** <-- ethers-js TransactionReceipt of an arbitrum tx */
)

/** Wait 3 minutes: */
await new Promise(resolve => setTimeout(resolve, 1000 * 60 * 3000))

// if dataIsOnL1, sequencer has posted it and it inherits full rollup/L1 security
const dataIsOnL1 = await l2TxnReceipt.isDataAvailable(l2Provider, l1Provider)

Bridging assets

Arbitrum SDK can be used to bridge assets to/from the rollup chain.The following asset bridgers are currently available:

  • EthBridger
  • Erc20Bridger

All asset bridgers have the following methods:

  • deposit - moves assets from the L1 to the L2
  • depositEstimateGas - estimates the gas required to do the deposit
  • withdraw - moves assets from the L2 to the L1
  • withdrawEstimateGas - estimate the gas required to do the withdrawal Which accept different parameters depending on the asset bridger type

Cross chain messages

When assets are moved by the L1 and L2 cross chain messages are sent. The lifecycles of these messages are encapsulated in the classes L1ToL2Message and L2ToL1Message. These objects are commonly created from the receipts of transactions that send cross chain messages. A cross chain message will eventually result in a transaction being executed on the destination chain, and these message classes provide the ability to wait for that finalizing transaction to occur.

Networks

Arbitrum SDK comes pre-configured for Mainnet and Goerli, and their Arbitrum counterparts. However, the networks functionality can be used to register networks for custom Arbitrum instances. Most of the classes in Arbitrum SDK depend on network objects so this must be configured before using other Arbitrum SDK functionality.

Inbox tools

As part of normal operation the Arbitrum sequencer will messages into the rollup chain. However, if the sequencer is unavailable and not posting batches, the inbox tools can be used to force the inclusion of transactions into the rollup chain.

Utils

  • EventFetcher - A utility to provide typing for the fetching of events
  • MultiCaller - A utility for executing multiple calls as part of a single RPC request. This can be useful for reducing round trips.
  • constants - A list of useful Arbitrum related constants

Run Integration tests

  1. First, make sure you have a Nitro node running. Check out the nitro repo, and run the following command ./test-node.bash --init --no-blockscout

  2. After the node has started up (that could take upto 20-30 mins), run yarn gen:network.

  3. Once done, finally run yarn test:integration to run the integration tests.

Defaults to Arbitrum Goerli, for custom network use --network flag.

Arbitrum Goerli expects env var ARB_KEY to be prefunded with at least 0.02 ETH, and env var INFURA_KEY to be set. (see integration_test/config.ts)

Bridge A Standard Token

Bridging new a token to L2 (i.e., deploying a new token contract) through the standard gateway is done by simply depositing a token that hasn't yet been bridged. This repo includes a script to trigger this initial deposit/deployment:

  1. clone arbitrum-sdk

  2. yarn install (from root)

  3. Set PRIVKEY environmental variable (you can use .env) to the key of the account from which you'll be deploying (account should have some balance of the token you're bridging).

  4. Set MAINNET_RPC environmental variable to L1 RPC endpoint (i.e., https://mainnet.infura.io/v3/my-infura-key)

  5. yarn bridgeStandardToken

Required CL params: networkID:number β€” Chain ID of L2 network l1TokenAddress:string β€” address of L1 token to be bridged

Ex: yarn bridgeStandardToken --networkID 421611 --l1TokenAddress 0xdf032bc4b9dc2782bb09352007d4c57b75160b15 --amount 3

More Repositories

1

arbitrum-classic

Powers fast, private, decentralized applications
Go
1,975
star
2

nitro

Nitro goes vroom and fixes everything
Go
738
star
3

arbitrum-tutorials

Get started developing on Arbitrum
JavaScript
451
star
4

stylus-sdk-rs

Rust Smart Contracts on Arbitrum
Rust
222
star
5

arbitrum-docs

Arbitrum Docs! Content + Webapp
MDX
180
star
6

arbitrum-token-bridge

πŸ’™ Interface for bridging assets to and from Arbitrum chains
TypeScript
153
star
7

token-bridge-contracts

Arbitrum token bridge and peripheral contracts
Solidity
149
star
8

bold

Efficient, all-vs-all dispute protocol for Optimistic Rollups
Go
111
star
9

eth-pos-devnet

Shell
111
star
10

stylus

Stylus VM and Fraud Prover
Go
107
star
11

nitro-contracts

The core Arbitrum Nitro contracts deployed to the parent chain to host the rollup
Solidity
97
star
12

arb-os

ArbOS operating system, to run at Layer 2 on Arbitrum chains. Also a compiler for Mini, the language in which ArbOS is written.
Rust
93
star
13

go-ethereum

Go
55
star
14

cargo-stylus

Cargo subcommand for developing Arbitrum Stylus projects in Rust
Rust
55
star
15

awesome-stylus

A curated list of Arbitrum Stylus code examples, libraries and resources
54
star
16

blockscout

Elixir
45
star
17

orbit-setup-script

TypeScript
42
star
18

stylus-hello-world

Project starter template for writing Arbitrum Stylus programs in Rust
Rust
39
star
19

arbitrum

35
star
20

arbitrum-orbit-sdk

πŸ’™ SDK for building Arbitrum Orbit chains
TypeScript
29
star
21

sszpp

C++ SSZ library
C++
25
star
22

arbitrum-token-lists

TypeScript
22
star
23

demo-dapp-pet-shop

Pet shop dapp, for use as an Arbitrum demo
JavaScript
20
star
24

arbitrum-orbit-deployment-ui

Introducing the L3 Orbit Chain Deployment Interface, a user-friendly tool to effortlessly deploy your own Layer 3 Orbit Chain. This repository streamlines the setup process, allowing developers to focus on their decentralized applications.
TypeScript
20
star
25

methodical-ssz

Code generation tool for adding Ethereum SimpleSerialiZe support methods to existing go types
Go
19
star
26

zig-on-stylus

EVM-interoperable smart contracts written in Zig!
Zig
18
star
27

nitro-testnode

A complete environment for nitro-based service including sequencer, batch-poster, validator, and a coordinator.
TypeScript
18
star
28

stylus-sdk-c

C/C++ Smart Contracts on Arbitrum
C
17
star
29

arbitrum-subgraphs

TypeScript
16
star
30

bold-validator-starter-kit

Starter kit repo for running Arbitrum BOLD validators
Shell
16
star
31

nft-bridge-workshop-demo

TypeScript
12
star
32

fund-distribution-contracts

Contracts for distributing rewards data availability committee members
Solidity
11
star
33

stylus-by-example

Simple examples of Arbitrum Stylus Rust & WASM smart contracts
MDX
11
star
34

arbitrum-monitoring

A collection of scripts designed for monitoring various aspects of Arbitrum chains.
TypeScript
10
star
35

Blobwatcher

Blob Monitoring Tool
Go
10
star
36

stylus-geth

Go
10
star
37

timeboost-design

Go
9
star
38

token-bridge-sdk

TypeScript
9
star
39

demo-dapp-election

JavaScript
9
star
40

stylus-sdk-bf

Bf Smart Contracts on Arbitrum πŸ˜…
WebAssembly
8
star
41

upgrade-executor

Support system for performing contract upgrades
Solidity
6
star
42

Arbiswap_V2_mono

TypeScript
6
star
43

arbitrum-cli-tools

TypeScript
6
star
44

community-helm-charts

Community Helm Charts provided by Offchain Labs
Smarty
6
star
45

retryable-tx-panel

TypeScript
5
star
46

actions

Collection of reusable GitHub actions and workflows
Shell
5
star
47

stylus-workshop-rust-solidity

Stylus workshop for interaction between Rust and Solidity
Solidity
5
star
48

stylus-contracts

Solidity
5
star
49

stylus-workshop-nft

Rust
5
star
50

config-monorepo

JavaScript
4
star
51

arbitrum-interop-quickstart

JavaScript
4
star
52

RescuETH

TypeScript
4
star
53

decentralized-timeboost-spec

4
star
54

keccak-const

Rust
4
star
55

arbitrum-deployment-website

Ethers interface form Arbitrum chain deployment
TypeScript
3
star
56

l1-l3-teleport-contracts

Solidity
3
star
57

crosschain-oracle-workshop-demo

Solidity
3
star
58

arb-compiler-evm-archive

Python
3
star
59

gnosis-safe-contracts

TypeScript
3
star
60

arb_reddit_community_points

TypeScript
3
star
61

deposits_tracker

TypeScript
2
star
62

stylus-erc20

Solidity
2
star
63

fastcache

Go
2
star
64

retryables_tracker

TypeScript
2
star
65

SoftFloat

SoftFloat-3e with WASM build support
C
2
star
66

wasmer

Rust
2
star
67

token-bridge-sdk-old

TypeScript
2
star
68

stylus-hello-world-minimal

Shell
1
star
69

orbit-actions

Solidity
1
star
70

encode-workshop-crosschain-messaging

JavaScript
1
star
71

token-mock

JavaScript
1
star
72

arb-provider-ethers-deprecated-

TypeScript
1
star
73

paired-erc20

Solidity
1
star
74

fakerdao

JavaScript
1
star
75

Arb-Burner-Wallet

TypeScript
1
star
76

arbtoken_twitter_faucet

TypeScript
1
star
77

ethers-bls-signer

TypeScript
1
star
78

arb-peripheral-template

An easy to use template to integrate with Arbitrum peripheral contracts
JavaScript
1
star
79

stylus-workshop-counter

Rust
1
star
80

stylus-chess

Rust
1
star
81

navigator

HTML
1
star
82

cuckoocache

Go
1
star
83

arb-ethers-web3-bridge

Arbitrum bridge for converting ethers provider into web3
JavaScript
1
star
84

arbitrum-funds-recovery-tool

Tool to recover funds that are stuck on an L2 aliased address
TypeScript
1
star