New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Write and Deploy a Smart Contract on Base

BaseSun, Nov 9, 2025, 12:00 AM

Learn how to write, deploy and test a simple smart contract on Base using Remix. 00:00 writing the contract 14:20 deploy the contract 16:15 testing on Base Sepolia Remix: remix.ethereum.org Full code and contract: https://repo.sourcify.dev/84532/0x87976224bed0A340258d562A8A1BAB8509412db0 These workshops are run by our internal Developer Relations Team, designed to teach you best practices coming from real-world Base experience. #OnchainAppInsights #web3 #accountabstraction #erc4337 #onchain #onchainApps #gasless #base #basechain #coinbasewallet #crypto #web3 #apps #blockchain

Transcript

Hi everyone. So today I will be showing you how you can write a smart contract, deploy it on base and test it. Uh I'll try to do it very very quickly in under 10 minutes. Let's go. So the first thing you do is you should go to remix.

ethereum.org, right? And then you create a new workspace. So when you click on create a new workspace, uh you should create a basic workspace. So I already have a workspace here.

It's a basic workspace. It's what you would get if you create a new workspace. So I think um yeah, you should start from there. Uh you can also start from the ERC 721, but I want to show you everything about what we're trying to do here. So uh I'll just start from this blank workspace.

And so first things first, uh let's delete these contracts that here. So let's delete the second one. Let's delete the third one. I will just keep the storage. I will rename this to NFT or ERC 721 mintable.

That's uh what I will rename it to. Um and then here I will rename I will say contract ERC 721 mintable and we'll start working on this. I will delete everything in here because it does not matter. Uh and this too as well. I think let's let's keep the the standard commenting.

Uh so title ERC 721 mintable dev it's a mintable ERC 721 contract and I think that will be it. So for now uh we will keep it so simple. Uh the first thing I will do is that we're not going to start from scratch to build an NFT contract. Right? We have some uh the contracts that most of the people in the industry use uh that are you know usually open ziplining contracts are ones that are pretty much often used for ERC20 and ERC 721.

So that's what we will do. We will create a very simple ERC 721. So an NFT contract that anyone can mint from if they pay a certain amount to USDC. I think that uh should be the the way to do it. uh for that to happen what I will do is I will import uh I need I will import open ziplin so it tells you okay this is good um so we can see here uh contracts I think there's one called there's a folder called token exactly and then ERC721 I do believe it does exist.

So there's here. So um so this is the contract we want to import. Um another thing you want to import is the interface. And the interface is the way uh through which we get to interact with um other contracts. So if you're trying to inherit uh so I what I will do here is you will see your C721 uh 721 mintable.

Okay. Yeah. One thing about solidity is that you have to import. Okay. Yeah.

We will work through that in a little bit. Okay. So we imported the ERC 721. Uh now what we will do is with that uh we will import an interface to interact with the ERC 20 which is USDC. Uh so that would be ziplining contracts and then I think it's interfaces and then I ERC20.

Exactly. So this is the way to do it. And then now that we have this uh what the way you can think about smart contracts is that they are almost like classes in in JavaScript. And so what you need to do is we need a constructor. Actually we need a constructor here.

And we have some cool uh some good constructor. Uh so okay this is interesting. So the ERC 721 itself as a contract uh let me see the depths if you go to the depths npm at open zeppelin token ER721. So ERC 7921 is itself as a contract it takes two variables in the constructor. So we need to pass that.

So as you can see here in the ERC 721 mintable we are inheriting all the the properties of ERC 721 and so one of them is the constructor and so that's where this error comes from. If you can see here it says no argument passed to the base constructor. So we need to pass arguments to the base constructor. How do you do that? You do something like this.

Okay so this is a good enough suggestion from the AI. Um this is a good enough suggestion from the AI but what I want to do even better than this is uh I will do something like this. I think you know we can take these and we can pass them again in our constructor and then here what we will do is that we will pass. Yes. Okay.

So this should work. So what what I did here is that you know whatever the ERC 721 uh constructor needs I am passing it to my constructor. So whoever is going to be creating this ERC 721 uh mintable um contract um will uh decide what would be the name and symbol for the NFT. And so you might be wondering like why are we recreating another 721? Why are we creating another NFT?

And so the reason for that is because the ERC 721 standard as it is written by Open Zeppelin here uh only has a bunch of functions and um none of them are necessarily a mint function uh that allows you to mint from uh outside of the contract. So let me explain. If you look at some of the functions here, uh a lot of the functions here are, you know, public view. So this makes the difference whether uh this function is shows to people from outside the contract where you can interact with it or whether the only way to call this function is through from the contract itself. And so as you can see here, some of the functions here are internal.

Uh and one of the functions that are internal is mint. And so one of the things that actually cool about uh you know solidity is that if it's an internal function usually it starts with uh with a um with uh an underscore. So um as you can see here the mint function starts with underscore and so underscore mint um is what allows us to know it's internal but mostly it's the fact that it's written internal here. Okay. So uh this function is internal.

I don't think there's any other function uh here that is a mint that's external. So we have another one called safe mint uh which is also internal. And so how do you use these functions if they are internal? There's a reason why they are internal and why they are there. And so the way to do that is we will create a function uh we will call it mint.

This is not too bad. Yeah. Mint address to. So where do you want to mint it to? And then a token ID.

I would say yeah let's let's let's say that you have to specify the token ID. And so for that what I will do is that I will just call the function mint. Remember the function mint already exists in this contract because we are inheriting all the functions of the previous ERC 721 contract. And so the way to do this is mint to token and then um yeah we can set the token IRI. So that's I'm I'm not going to go there.

This is an interesting suggestion from the AI. But for now I will just keep it this way. If you do this actually and we close the function. Uh so this should allow us to so first of all this compiles and I click uh uh command S. You can see here it compiles.

You can click compile. It compiles. So it works. Uh and so this allows us allows us to you know deploy an ERC 721 that anyone can mint from. There are no restrictions on who can mint.

It does not ask you to uh uh send USDC before you can mint. But um I'll do something else here uh which will get us into the territory of above 10 minutes. But but it's okay. I think it I think it is worth it. Um and so the way this will be done is I will create an ERC20 uh let's call it USDC.

Um, so this will be USDC contract. It's going to be an IRC20 USDC contract. So I think I think this could be H public immutable. No, it doesn't have to be mutable. Uh, and yeah, I think this should be it.

And let me create another function. Call it set. Um, okay. Let me just hardcode the USDC. This is Don't do this.

It's not good. Don't hard code the USDC contracts. The the way to do it is you should set a function. Let's say that says set USDC and it takes you know an address and USDC and then what it does here is that it will uh do something like USDC takes IRC20 USDC and then we close it and that's it. So usually you should see you should you should set this function and hopefully it's only owner or something like that.

So this is not you know configured uh but but for now so that I don't go too deep into the rabbit hole uh what I will do is I will hardcode the USDC okay and so for that it will be something like this IRC20 and then we do this I think this should work so this is USDC on base where we will be deploying our contract so for Now, it's a contract that only that mints regardless of uh whether or not you did send um a USDC transfer. So, USDC. So, this is something also that's interesting because USDC has six decimal. So, let's assume that we're asking for one USDC. USDC has six decimal.

Um I think this is something that if you look at the USDC tracker here. Yes. So as you can see I'm going to show you here the USDC contracts on basipoleia it says that it has six decimals. There's different way to look at it too. You can try to read the contract here.

And I think there must be a uh decimals. Yes, there's a decimals function and it's six decimals. So, so the one, so when it's six decimals, the way that solidity works, there are no um decimals. Uh you will have a representation in uh u so in uh signed integers and so uh this is the representation of one USDC in solidity. It's it's uh 1 million uh units of small small units of USDC.

And so uh that's how it works. So what did you write here? What did the AI actually help us write here? And what we did is that uh we have require USDC.t transfer from.

So we're transferring from the message sender, the person that's you know making the call to the address of the contract. We're transferring one USDC for every mint. Um, now you can think of a way to recoup this money that gets accumulated in the contract. You can route uh the the USDC to a to a different address. Again, we're not playing by the book here.

We're trying to do everything very quickly. And so we're just going to send the SDC to this contract. And so for now, this should be good. Uh, now you can actually deploy the contract. Um, and for that what we will do, we'll try to deploy it to base Solia.

I think uh hopefully at some point we get to uh have better support for smart wallets uh at Remix including being able to switch the chain from Remix itself or using create to instead of create but for now we will um use Metam mask um EOA. So let's see. So I think it's already set on base. I have some ETH and so it allows you to deploy and verify. You get to verify on explorers.

If you add I think if you add the API uh ether scan API key you can go set it in the settings panel. Uh I think it's somewhere here. Where is it? Yeah, I think it's here. You get to set the the API address the API key for for each of scan if you want.

Uh but for now I think this comes from here. Yeah, exactly. Access token. You can create a new API key and save it and that would um verify on ether scan. I'm not going to do that.

I'm going to show you another one which is Cersify that I discovered lately that was actually pretty cool. So let me choose the name and the symbol. I will be putting base and base here at both and I will transact very simply and it will prompt me to deploy the contract. So I'll wait for the contract to be deployed here. Uh let's see it is create being created and here we are.

So we have the contract here ERC 721 mintable and we will be able to mint before we are able to mint. So let's actually try and try to mint here to my address. Try to mint token zero. And as you can see here, there's an error. Execution reverted.

ERC20 transfer amount exceeds allowance. So what this means is that we need an approval to the contract to the ERC 721 mintable contract before we are able to move USDC from my wallet to the contracts wallet. and and so uh I will hit send transaction anyway and you will see that the transaction will fail. So as you can see here the transaction fails miserably uh because it exceeds the allowance. So one thing that I noticed also is that uh in this contract I thought I put one USDC I actually put 10 USDC.

So let me get some USDC faucet uh for me to be able to pay for this NFT contract and I'll be back. Okay. So, I want to show you here how to do that. You go to faucet.circle.

com and you get some USDC sapoleia. So, we're getting 10 USDC. Exactly what we need for us to pay for this uh NFT. So, how do I call the approved uh function? Where is it?

So, the approved function is on the USDC on base. uh and so I need to get the USDC contract address and I will load it. So I will load an interface of USDC contract address so that I can interact with it from remix itself. Uh another way obviously you can interact with that contract is through the explorer itself. So you can go to contract uh write as proxy and you can you know interact here through approve.

I will do it through remix. Um okay. So let's go back to remix. I will load the IRC20 contract here. Uh they have this cool function where you could do add address which allows you to interact with a deployed contract.

So uh I load the ERC20 contract here and I can hit approve. Who's going to be the spender? Well, the spender is going to be the the ERC 721 mintable contract. And then how much value am I going to allow it to spend? uh it's going to be 10 USDC which is uh one and then seven zeros because as you remember USDC has six decimals.

So these are the decimals and this is the USDC 10 USDC with six decimals. So I will hit transact here and let's see. So yeah this actually you're giving someone else permission to spend this amount from your account and so I will just hit transact here. Done. Transacted.

Cool. Great. Uh, now that this has been done, I should be able to go back to my ERC 721 uh, mintable and be able to mint. Let's see if it works. And lo and behold, it seems to be working.

Uh, I didn't get a message that says that the uh, allowance is exceeded. So, here. And let's see if the mint. So the mint contract is pending. Um I'm not sure if it went through.

Yes. So this is the transaction went through. All good. Perfect. Uh nothing wrong with this.

Um yeah, amazing. And as I can see here, if I go and actually see it, took a look at the ERC 7921 contract that I have. As you can see, there was a mint call. So the first mint call failed and the second mint call succeeded. So yeah, this is how you can run your test.

This is how you can deploy simple contract. Uh I will be sharing the sourceify uh link is what I discovered from remix lately and so it has everything you need. It has the code. I'll share this in the comments of this video. Thank you everyone for watching and yeah this was not exactly 10 minutes but I hope it was um it was resourceful and helpful for you to to learn uh or start learning some smart contracts development.

Let me know if you like this kind of content. Let me know if you like this kind of content. I can do more of it and appreciate you watching to this point. See you soon.

Automatic transcript — names and jargon may be misspelled.