Quickstart For Developers
This quickstart is for web developers who want to start building decentralized applications (dApps) using Camelot. It makes no assumptions about your prior experience with Ethereum or Solidity. Familiarity with Javascript and yarn is expected. If you're new to Ethereum, consider studying the Ethereum documentation before proceeding.
A.How to Write a contract
We're going to build a digital cupcake vending machine using Solidity smart contracts. Our vending machine will follow two rules:
1. The vending machine will distribute a cupcake to anyone who hasn't recently received one.
2. The vending machine's rules can't be changed by anyone.
Here's our vending machine implemented as a Javascript class:
VendingMachine.js
The VendingMachine class uses state variables and functions to implement predefined rules. This implementation is useful because it automates cupcake distribution, but there's a problem: it's hosted by a centralized server controlled by a third-party service provider.
Let's decentralize our vending machine's business logic and data by porting the above Javascript implementation into a Solidity smart contract.
Create a decentralized-cupcakes directory for your project and install hardhat using VS Code's integrated terminal:
This installs two packages: hardhat lets us write, test and deploy our smart contracts, and hardhat-toolbox is a bundle of popular Hardhat plugins that we'll use later.
Next, run yarn hardhat init to configure Hardhat. Select Create a JavaScript project when prompted. Make sure you specify your decentralized-cupcakes directory as the project root when asked.
At this point, you should see the following items (among others) in your decentralized-cupcakes project directory:
Replace the contents of hardhat.config.js with the following:
Before compiling the default contracts, you will need to install additional dependencies. Run yarn hardhat compile and expect it to fail for the first time — follow those instructions, then run yarn hardhat compile again until it runs successfully. You should see Compiled 1 Solidity file successfully in the terminal output. You should also see a new decentralized-cupcakes/artifacts/ directory. This directory contains the compiled smart contract.
Open scripts/deploy.js and replace its contents with the following:
We'll use this to deploy our smart contract in a moment. Next, delete contracts/Lock.sol and replace it with contracts/VendingMachine.sol, the smarter alternative to our Javascript implementation:
Note that this smart contract is written in Solidity, a language that compiles to EVM bytecode. This means that it can be deployed to any Ethereum-compatible blockchain, including Ethereum mainnet, Arbitrum One, and Arbitrum Nova.
Run yarn hardhat compile again. You should see Compiled 1 Solidity file successfully in the terminal output. You should also see a new decentralized-cupcakes/artifacts/contracts/VendingMachine.sol directory.
B.How to Depoly a contract to the Camelot testnet
We were able to deploy to a local testnet for free because we were using Hardhat's built-in Ethereum network emulator. Camelot's testnet is powered by a real network of real nodes, so we'll need to pay a small transaction fee to deploy our smart contract. This fee can be paid with the Camelot’s testnet's token, $BTC.
First, update the hardhat.config.js file to specify the private key of the test account that you'll use to deploy your smart contract (and pay the transaction fee):
Next, let's deposit some $BTC into the wallet corresponding to the private key we added to hardhat.config.js.
Once you've acquired some $BTC, you'll be able to deploy your smart contract to Camelot’s testnet by issuing the following command:
Congratulations! You've just deployed business logic and data to Camelot Testnet.
To view your smart contract in a blockchain explorer, visit
https://testnet-scan.cam3lot.io
C.RPC endpoints
Camelot is EVM compatible, you can connect to Camelot via your familiar EVM wallet as usual.
Here is the public RPC endpoints you can use:
Mainnet(Coming Soon)
Testnet
Network name: Camelot Testnet
RPC URL: https://testnet-rpc.cam3lot.io
Chain ID: 52001
Currency symbol: BTC
Block explorer URL: https://testnet-scan.cam3lot.io
Last updated