The OP Stack is a modular framework that enables developers to launch their own rollups by combining a consensus client (OP Node) with an execution client (OP Go), along with a Batcher for posting transactions to Layer 1 and a Proposer for managing withdrawals; the process involves cloning the monorepo, generating keys for different roles (admin, proposer, Batcher), configuring the network with L1 starting block information, deploying smart contracts, initializing both clients with genesis files and JWT tokens, and finally running both components to produce blocks and process transactions.
Build a Rollup with OP Stack: Full Technical Tutorial
Added:[Music] hello oh look at that if I talk like uh is it loud enough all right a bit closer all right yeah that's good all right I'm I'm all right we got some stragglers if you this is unrelated to the talk but if you want to be added to my um hackathon social graph come talk to me afterwards and I'll add your address to this this is all the people that I've met at the hackathon all right um here's what we're going to do we're gonna we're going to launch a a rollup in 30 minutes this time if I fail I'm not going to shave my head I already did that um so you're just going to have to trust me yeah yeah yeah yeah exactly well last time to be clear I I did do a thing where I said I would do this in 30 minutes or I would shave my head and my computer crashed so it was the computer's fault but I I you know whatever my hair is growing back so it is what it is all right so um you know some context here really quickly uh you know optimism is building has been building stuff for a long time time we've been building this blockchain op main net um and we were like hey you know people are starting to use this code uh to run their own stuff why don't we just like make that official and um and make it really easy for people to spin up their own rollups using our code and then they can they can help us build the software because they'll be using the same code and so then they'll be help you know they'll be building the software too and everyone kind of wins um so we came up with this thing called the op stack which is basically the code that powers the the the optimism Collective and and um you know it does a lot of things but one of the most important things that it does is it it you can use it to run a rollup um so there are easier ways in practice to actually run these things people now have built you know tooling on top of this where you can really it's it's close to one click to deploy these things there's things like conduit um and uh and Caldera and these companies now that are spinning up that'll help you run a rollup but if you want to understand kind of what's going on under the hood and the different components involved it's nice to be able to do it from source and to kind of just spin up each of the components one by one and get a good sense of what's happening so um this is kind of the the slightly more indepth version uh than in practice what people would be running in production but it's worth understanding this so you know we're going to be we're going to be doing it from source which is you know it's always more fun so okay so the you can follow along with this if you want if you go to stack.
optimism. and you go to the getting started page um I'm going to keep this like on the left here but I'm really just going to be talking about it so you don't have to see that and maybe I should make my vs code a little bigger okay um yeah so a lot of the op stack code lives in the optimism monoo big old monoo so you know just clone it start with that pretty easy um and the monor repo has some stuff that you need some stuff that you don't need so we're just going to build some of it but it's really pretty straightforward this is going to like I don't know who knows if we even take take 30 minutes we'll find out all right boom optimism right we got the monor repo here there's a bunch of stuff in it don't worry about it we'll get there is this too small should I make this bigger all right good um obviously install dependencies whatever that's going to take a minute it always takes a minute whatever how how's everyone doing um you good life good okay I'm I swear to God I'm not shaving my head again all right all right as long as I can have 40 minutes all right so this is this is uh all right we're done right so we installed our dependencies um and then we're just going to make some of the components so I'll tell you in a second what these are so generally speaking an Opie stack system or just a client for for this system is broken up into two key components just like in ethereum you have a consensus client and an execution client we essentially have the same split there's this thing called the op node the op node that's the that serves as the consensus client and then there's a another component that serves as the execution client and now there's actually multiple implementations of this so we have two two implementations of the of the consensus client that's op node and Magi which is the uh the version that a16z built and then we also have two execution client options there's op gu and op Aragon which are just slight modifications to gu and Aragon that make them work as you know our execution client so you can mix and match between these things you can run op node with OP G where you can run Magi with OP Aragon or whatever combination you want just like you can in ethereum um right now we're going to use op node and op gu that's just sort of the reference implementations that op Labs has been working on and so every single client in the network runs these two services for itself right just like in ethereum you run a consensus client and an execution client we're doing the same thing and uh and then there's these other things called the Batcher and the proposer so the Batcher is a process that talks to the sequencer node and it gets all the data from the sequencer and puts it on on uh L1 in this case we're going to be using gley so it puts it on Gurley and the proposer is something that exists for now but won't exist relatively soon which is something that sort of proposes what the output of the L2 is to the main Bridge uh which allows users to then withdraw funds from the main Bridge um if you don't you know for testing you technically don't need to run the proposer but why not but you do need to run the bad and you need to run One op node op gu pair together which forms one node we're only going to be running one node right now which is the sequencer node but you can also just attach more nodes and they'll communicate over PE like a peer-to-peer Network and share blocks with one another and that all just happens kind of automatically which is nice so the only other thing is that we we've separated um we've separated gu out into its own repo we usually do everything in the monor repo but we gu specifically we like to have a very minimal diff on top of gu that that's what keeps things simple so there's actually a website that you can go to which is op.
optimism. there we go if you go to op.
optimism. you can see a detailed description of every single line of codee that we have changed inside of gu and what it does so if you're curious as to what the diff actually achieved go to op. op. you can see every single line of code with a detailed description of why that line was changed um Okay so we've separated out gu and we have to make gu same way you make gu normally it just builds so that takes a second and we'll also need access to a girlyy node so we're going to be attaching this to girly but you can attach this to any chain as an L1 any evm chain um could put it on polygon put it on whatever you want doesn't really matter as long as it's an evm blockchain you can use it as the L1 girly is just easy uh and if you need girly just asked me I have an enormous amount of girly East to give away so just let me know all right cool so we've built most of the software now it's just sort of about configuring it and running it which is really really simple um for the sake of this demo we're going to generate some some keys there we go so if you go to the contracts Bedrock repo Bedrock is our upcoming upgrade that's that runs all this stuff um we have this command oops this re key command the re key command just generates random random private keys for you um so I'm just going to take a just going to copy that uh you don't need to use this you can use your own Keys your own accounts this is just a useful thing to quickly generate private keys and and accounts that you can use uh and you need to fund them so these numbers here are pretty pretty high I don't think you actually need these this much e in them um right now but gurly gley sometimes gets very expensive at random points um like last week when it was like 10,000 glay which is ridiculous so uh some you know I recommend probably doing this on sapoia like some other network other than girlyes because girly is kind of kind of a mess sometimes but yeah so you need to fund all of these wallets with a certain amount of eth there's an admin key that that deploys all the smart contracts there's the proposer key which is going to propose those outputs and then there's the Bacher key which is going to post that that L2 transaction data to L1 each one of them needs a slightly different amount of eth um these are suggested numbers but you can do more or less or whatever so the next thing so we've just generated Keys the next thing to do is to configure the network so to configure the network uh We've we've kind of done a lot of the work for you as part of this demo um where are we so packages contracts bedrock and so if you go to the deploy config folder inside of contracts Bedrock there's a getting started Network and the getting started network has what you need to fill in um all you need to fill you need to fill in a couple things and the uh really most of this is pretty simple you fill in the admin uh what says admin with the admin key that you got whenever it says proposer with the proposer key whatever says Bachelor with the bachelor key it's just find and replace so that part is pretty simple we'll do that in a minute the other thing is a every Bedrock chain needs to sort of tie itself to a to an L1 block that it it sort of starts from that's where it starts you know the chain starts looking at data after that L1 block so we're just going to go ahead and um and find that block I'm realizing now that I need to I need to get myself an Alchemy endpoint all right give me a second here okay so girly right great copy that okay so um it's usually recommended to grab a finalized block just why not and then we're just going to grab some of the some of the fields so we want the time stamp the hash and the block number pretty simple so we pull that out here's the so we're just going to use block 8,988 274 is our starting block for the network uh this is the hash of that block and this is the time stamp of that block so we're going to take that hash and we're going to stick it into this thing that says L1 starting block tag and we're going to take that Tim stamp and we're going to stick it into the thing that says L2 output Oracle starting Tim stamp and then the rest of this is pretty simple we just kind of go back and forth finding and replacing uh so we got admin here we're going to find and replace that with the the admin address don't worry about it uh we've got sequencer going to replace that with the sequencer address proposer and Bater we could probably automate this more but again like in practice you aren't really going to be doing it like this you'll be using more tooling to automate all this stuff this just gets you a sense of where the config actually comes from so that's the First Step um now we have a configured Network we basically just need to uh deploy our contracts so that's simple enough we're going to create a EnV file or you can copy this.v file I guess um whatever I don't really care about any of that we need two things we need the uh RPC that we got from alchemy that the L1 RPC and we need the private key of the account that's going to deploy everything in this case the private key of the account that's going to deploy everything is the admin key so that's simple enough um the last thing is just you need to send money to the admin key otherwise you can't do anything so I'm going to have my whale account send some money to the admin key come on what's it doing I blame the internet okay all right e on op girly wait that's op gurly I don't want op girly I want Ethan Gurley what is it doing do I do I not have Chans Bly there you go that's why okay huh oh this is frame this is a very good wallet if you're interested worth worth worth trying in my opinion um all right we're going to send girly eth I'm going to send five girly eth to oops to my admin admin wallet here uh if I can find it Jesus must where is it doing all right yeah great all right sign send fantastic done okay so my admin key has eth now pretty simple uh now I just deploy a bunch of contracts you know there you go all right so hopefully that was enough e and I can just start deploying stuff maybe okay so this is the part that kind of takes a while which is really annoying um we basically just sit here and deploy a bunch of smart contracts so that's just going to start happening uh in the meantime I can kind of talk about what we're going to do next it's pretty straightforward so the where are we yeah so we at once all the smart contracts get deployed we basically just have to configure the op node and configure op gu um the op node is going to generate a Genesis Json file which is the same or it'll it'll it has a command to generate a Genesis Json file that's the same type of Genesis Json file you would expect for any network same thing um and a rollup Json file which just has some config config values in it and then we need a uh JW T token for the communication between the op node and op gft that's exactly how it works in ethereum as well it's not different so you know same concept and and then we're going to initialize op gu we're basically just going to insert the sequencer key into the uh into GI which we can actually do now while this is happening to save some time here so we can uh make a directory we're just going to call it data dur oops whoops that's not there we go um we're going to create a password in this case the password is password so probably use a real password in production uh but whatever and then we're going to take the sequencer key and we're going to dump it into a file easy and now we're just going to import that sequencer key so should just be able to import it boom so now we've imported the sequencer key you can see this this address here is the same address that's been imported and then once we're done with the other thing we're going to we're going to initialize GI with the Genesis Json which is how this is exactly how you would initialize GI in ethereum as well so we're almost done here once all the smart contracts get deployed this is actually really fast girly is usually not this fast so I'm I may actually make it today we'll see well in the meantime while this is happening we can also set up the command for initializing the op node we won't run it yet but we'll get there so uh you know what I'm just going to copy this you can just copy paste this I don't know why I'm pasting it like that oh and I forgot my where's my Alchemy all right whatever copy we should paste that in there too all right so once this is done deploying I'll just run this command we're almost there this is the slow part so close we'll be there in a minute I don't know any questions in the meantime probably got like five minutes it's pretty simple you just follow the instructions and then at the end of this you have a roll up so you know um the fun stuff though is to go in and actually hack on it which you can do so you can you know there's a it inside the op stack docs there's a lot of explainers for uh what we call op stack hacks which are things you can do to mess with the op stack so you can do things like add a pre-compile um you can manipulate the derivation function so the derivation function is the piece of code that looks at the uh transactions on L1 and figures out what the L2 blockchain should look like as a result uh but you could do stuff like one of the examp examples that we give is have something that automatically tracks the burn on L1 so every single block track how much you know how much gas is being burned in that block and automatically update a smart contract nl2 to reflect that new thing so you get essentially the way that you can think of um the way you can think of all these chains is that they're really just indexers on the L1 State and we made it really easy to modify the indexer so you can index all sorts of stuff you could like a a blockchain that only exists to index Unis swap trades or you could have like an oracle on Layer Two that automatically pulls in chain link updates from L1 and makes them immediately available on L2 so there's a lot of different things you can do but that in order to do that you just need to modify the uh the derivation function and there's a tutorial in here about oh how you can modify that derivation function index it T yeah so so the question was if you wanted to index like every block and every you wanted to index every transaction as well you can you can index literally whatever you want yeah you could build like a whole block Explorer that's actually a rollup like like a rollup that indexes a whole bunch of stuff on L1 and then pipes that data into smart cont on this layer two and then the cool thing is that the whole thing is you can you can like fault prove it right like you could run these optimistic fault proof so then not only can you like have a rollup that's actually an indexer you can also have Smart contracts on layer one that like read the data from the roll up and act on the RO on that data so I mean it depends on how fast you want like your proving time to be you know like I mean you can make it if if you're okay with the security properties you can make it like 30 minutes or an hour or something like that um you know and eventually you'll have ZK proofs to be able to do the same thing to be able to prove it pretty much immediately so you know the future of this is that you have these very very detailed indexers that then then report data back to layer one so the like the layer one smart contracts can just access like all of the information of every other smart contract in an extremely efficient way um okay great great wait what is this off phase two did they change so here's the other thing about this is that the um is that we're we're also modifying this at the same time I'm I'm not surprised if they did not update my no wait face two wait phase two oh okay wait wait wait wait I think this is good I think we're done we're done we're done okay great so I should just be able to configure this now boom all right so I have my Genesis Json file that I just generated I'm going to generate a Json web token as well so I've done that I'm going to copy that so I'm going to copy Genesis Json [Music] into op gu I'm going to copy the JWT into op gu all right we might not get around to running the Bater but you'll get there okay now we just initialize gu that's easy enough I just run that initialization thing boom we're done initialized um uh okay so the next thing is to run op gu I just need to export a couple things into export whatever come on all right we have to automate this a little more the thing is we didn't want people to Auto we didn't want to automate the tutorial too much because then people would be really confused about what was happening under the hood but I don't know oh that's the wrong thing too CH ah all right just follow this export all the things that you need to export and the address of the L2 output Oracle is the last thing that we need I don't know why we need this to play ments getting started L2 output Oracle froxy okay all right so hopefully this just works now okay all right so gu is running that's simple um and now we just need to run the the op node hopefully and of course that doesn't work because in a different terminal okay so all all right let me minimize this this so we have the two things running um yeah so pretty simple at this point we have the we have op gu running we have the op node running it's essentially iterating over the chain and figuring out when you know it's it's just loading bits of the chain right now it has to catch up so we're at 327 I don't know what the current girly do what's the current block current block is 397 so if you give it a second in uh in a few seconds it's going to start producing blocks at this point it's going to start producing empty blocks uh and I've been told that we have to kill it there but if you keep following this uh it's I mean at that point we have we have a a a sequencer running at this point so then we just start submitting it you just have to run this Batcher program and that's it you just you just make sure that the Batcher has some eth start running and you have a roll up and then you can do whatever you want so start messing with it there you go it's producing empty blocks start sending it transactions it'll produce non-empty blocks all right I'm getting kicked out but if you want to keep chatting later go to stack.
optimus. have fun mess around do crazy stuff and uh I'll be here all right bye
Up Next

Defining Active Users in Crypto: Solana vs Ethereum Metrics
@LightspeedpodHQ
2K views•2024-02-29

Hybrid Key Establishment in Production: Post-Quantum Cryptography
@durumcrustulum
14.7K views•2025-08-27

ERC-4337 Account Abstraction via Alternative Mempool | Ethereum Foundation Talk
@ETHGlobal
6.2K views•2022-04-27

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto







































