Skip to content

Commit 16b49c3

Browse files
authored
Merge pull request #131 from OffchainLabs/update-tutorials-7
Update non-SDK tutorials
2 parents 10d218c + 1ae0f29 commit 16b49c3

File tree

13 files changed

+119
-114
lines changed

13 files changed

+119
-114
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# This is a sample .env file for use in local development.
22
# Duplicate this file as .env here
33

4-
# Your Private key
5-
DEVNET_PRIVKEY="0x your key here"
4+
# Your private key
5+
PRIVATE_KEY="0x your key here"
66

7-
# Hosted Aggregator Node (JSON-RPC Endpoint). This is Arbitrum Sepolia Testnet, can use any Arbitrum chain
8-
L2RPC="https://sepolia-rollup.arbitrum.io/rpc"
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/demo-dapp-election/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
# demo-dapp-election Tutorial
1+
# demo-dapp-election tutorial
22

3-
demo-dapp-election is a simple sample example that allows you to deploy the Election contract to Arbitrum and run its functions.
3+
`demo-dapp-election` is a simple sample example that allows you to deploy the Election contract to Arbitrum and run its functions.
44

5-
The contract lives entirely on L2 / involves no direct L1 interacts; writing, deploying, and interacting with it works just like using an L1 contract.
5+
The contract lives entirely on the targetted chain, and involves no direct interacts from the parent chain; writing, deploying, and interacting with it works just like using a regular contract on Ethereum.
66

7-
## Config Environment Variables
7+
## Set environment variables
88

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

11-
```bash
11+
```shell
1212
cp .env-sample .env
1313
```
1414

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

17-
### Run Demo
17+
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.
1818

19-
```bash
19+
## Run demo
20+
21+
```
2022
yarn run exec
2123
```
2224

23-
## Curious to see the output on the Arbitrum chain?
24-
25-
Once the script is successfully executed, you can go to the [Arbitrum block explorer](https://sepolia.arbiscan.io), enter your L2 address, and see the corresponding transactions on the Arbitrum chain!
26-
2725
<p align="left">
2826
<img width="350" height="150" src= "../../assets/logo.svg" />
2927
</p>

packages/demo-dapp-election/contracts/Election.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pragma solidity ^0.7.0;
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
23

34
contract Election {
45
// Model a Candidate
@@ -19,7 +20,7 @@ contract Election {
1920
// voted event
2021
event votedEvent(uint256 indexed _candidateId);
2122

22-
constructor() public {
23+
constructor() {
2324
addCandidate("Candidate 1");
2425
addCandidate("Candidate 2");
2526
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require('@nomiclabs/hardhat-ethers')
2-
32
const { hardhatConfig } = require('arb-shared-dependencies')
43

54
module.exports = hardhatConfig
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
{
22
"name": "demo-dapp-election",
33
"license": "Apache-2.0",
4+
"author": "Offchain Labs, Inc.",
45
"version": "1.0.0",
56
"scripts": {
67
"build": "hardhat compile",
7-
"exec": "hardhat run scripts/exec.js --network l2"
8-
},
9-
"devDependencies": {
10-
"@nomiclabs/hardhat-ethers": "^2.0.2",
11-
"chai": "^4.3.4",
12-
"ethers": "^5.1.2",
13-
"hardhat": "^2.2.0"
14-
},
15-
"dependencies": {
16-
"dotenv": "^8.2.0"
8+
"exec": "hardhat run scripts/exec.js"
179
}
1810
}

packages/demo-dapp-election/scripts/exec.js

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,83 @@
1-
const hre = require('hardhat')
21
const { ethers } = require('hardhat')
2+
const { providers, Wallet } = require('ethers')
33
const { expect } = require('chai')
4-
54
const { arbLog, requireEnvVariables } = require('arb-shared-dependencies')
65
require('dotenv').config()
6+
requireEnvVariables(['PRIVATE_KEY', 'CHAIN_RPC'])
77

8-
requireEnvVariables(['DEVNET_PRIVKEY', 'L2RPC'])
8+
/**
9+
* Set up: instantiate wallets connected to providers
10+
*/
11+
const walletPrivateKey = process.env.PRIVATE_KEY
12+
const chainProvider = new providers.JsonRpcProvider(process.env.CHAIN_RPC)
13+
const chainWallet = new Wallet(walletPrivateKey, chainProvider)
914

1015
const main = async () => {
1116
await arbLog('Simple Election DApp')
1217

13-
const l2Wallet = (await hre.ethers.getSigners())[0]
14-
console.log('Your wallet address:', l2Wallet.address)
15-
16-
const L2Election = await (
17-
await ethers.getContractFactory('Election')
18-
).connect(l2Wallet)
19-
console.log('Deploying Election contract to L2')
20-
const l2election = await L2Election.deploy()
21-
await l2election.deployed()
18+
/**
19+
* Deploying the Election contract
20+
*/
21+
const Election = (await ethers.getContractFactory('Election')).connect(
22+
chainWallet
23+
)
24+
console.log('Deploying Election contract')
25+
const election = await Election.deploy()
26+
await election.deployed()
2227
console.log(
23-
`Election contract is initialized with 2 candidates and deployed to ${l2election.address}`
28+
`Election contract is initialized with 2 candidates and deployed to ${election.address}`
2429
)
2530

26-
//Fetch the candidate count
27-
const count = await l2election.candidatesCount()
31+
/**
32+
* Fetch the candidate count
33+
*/
34+
const count = await election.candidatesCount()
2835
expect(count.toNumber()).to.equal(2)
2936
console.log('The election is indeed initialized with two candidates!')
3037

31-
//Fetch the candidates values (id, name, voteCount) and make sure they are set correctly
32-
var candidate1 = await l2election.candidates(1)
38+
/**
39+
* Fetch the candidates values (id, name, voteCount) and make sure they are set correctly
40+
*/
41+
var candidate1 = await election.candidates(1)
3342
expect(candidate1[0].toNumber()).to.equal(1)
3443
expect(candidate1[1]).to.equal('Candidate 1')
3544
expect(candidate1[2].toNumber()).to.equal(0)
3645

37-
var candidate2 = await l2election.candidates(2)
46+
var candidate2 = await election.candidates(2)
3847
expect(candidate2[0].toNumber()).to.equal(2)
3948
expect(candidate2[1]).to.equal('Candidate 2')
4049
expect(candidate2[2].toNumber()).to.equal(0)
4150
console.log('candidates are initialized with the correct values!')
4251

43-
//Cast a vote for candidate1
52+
/**
53+
* Cast a vote for candidate1
54+
*/
4455
var candidateId
4556
var candidate
4657
var voteCount
4758
candidateId = 1
4859

49-
const voteTx1 = await l2election.vote(candidateId)
60+
const voteTx1 = await election.vote(candidateId)
5061
const vote1Rec = await voteTx1.wait()
5162
expect(vote1Rec.status).to.equal(1)
52-
console.log('Vote tx is executed!')
63+
console.log('Vote transaction is executed!')
5364

54-
const voted = await l2election.voters(l2Wallet.address)
65+
const voted = await election.voters(chainWallet.address)
5566
expect(voted).to.be.true
5667
console.log('You have voted for candidate1!')
5768

58-
//Fetch the candidate1 voteCount and make sure it's equal to 1
59-
candidate = await l2election.candidates(candidateId)
69+
/**
70+
* Fetch the candidate1 voteCount and make sure it's equal to 1
71+
*/
72+
candidate = await election.candidates(candidateId)
6073
voteCount = candidate[2]
6174
expect(voteCount.toNumber()).to.equal(1)
6275
console.log('Candidate1 has one vote!')
6376

64-
//Fetch Candidate2 and make sure it did not receive any votes yet
65-
candidate = await l2election.candidates(2)
77+
/**
78+
* Fetch Candidate2 and make sure it did not receive any votes yet
79+
*/
80+
candidate = await election.candidates(2)
6681
voteCount = candidate[2]
6782
expect(voteCount.toNumber()).to.equal(0)
6883
console.log('Candidate2 has zero vote!')
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# This is a sample .env file for use in local development.
22
# Duplicate this file as .env here
33

4-
# Your Private key
5-
DEVNET_PRIVKEY="0x your key here"
4+
# Your private key
5+
PRIVATE_KEY="0x your key here"
66

7-
# Hosted Aggregator Node (JSON-RPC Endpoint). This is Arbitrum Sepolia Testnet, can use any Arbitrum chain
8-
L2RPC="https://sepolia-rollup.arbitrum.io/rpc"
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"
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
# demo-dapp-pet-shop Tutorial
1+
# demo-dapp-pet-shop tutorial
22

3-
demo-dapp-pet-shop is a simple sample example that allows you to deploy the adoption contract to Arbitrum and run its functions.
3+
`demo-dapp-pet-shop` is a simple sample example that allows you to deploy the adoption contract to Arbitrum and run its functions.
44

5-
The contract lives entirely on L2 / involves no direct L1 interacts; writing, deploying, and interacting with it works just like using an L1 contract.
5+
The contract lives entirely on the targetted chain, and involves no direct interacts from the parent chain; writing, deploying, and interacting with it works just like using a regular contract on Ethereum.
66

7-
## Config Environment Variables
7+
## Set environment variables
88

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

11-
```bash
11+
```shell
1212
cp .env-sample .env
1313
```
1414

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

17-
### Run Demo
17+
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.
1818

19-
```bash
19+
## Run demo
20+
21+
```
2022
yarn run exec
2123
```
2224

23-
## Curious to see the output on the Arbitrum chain?
24-
25-
Once the script is successfully executed, you can go to the [Arbitrum block explorer](https://sepolia.arbiscan.io), enter your L2 address, and see the corresponding transactions on the Arbitrum chain!
26-
2725
<p align="left">
2826
<img width="350" height="150" src= "../../assets/logo.svg" />
2927
</p>

packages/demo-dapp-pet-shop/contracts/Adoption.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pragma solidity ^0.7.0;
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
23

34
contract Adoption {
45
event PetAdopted(uint256 returnValue);

0 commit comments

Comments
 (0)