Setting up the Timelock Wallet project
In this guide, you’ll learn how to deploy your first smart contract on the Nexus Layer 1. We’ll walk you through creating a Timelock Wallet - a simple but powerful contract that demonstrates fundamental blockchain concepts. What you’ll accomplish:- Set up a complete development environment using Hardhat
- Configure your wallet and obtain test NEX tokens
- Write, compile, and deploy a timelock smart contract
- Verify your contract on the Nexus blockchain
- Interact with your deployed contract through scripts
- Creating savings accounts with built-in discipline
- Setting up vesting schedules for tokens
- Building escrow mechanisms for time-sensitive agreements
What Is a Smart Contract?
A smart contract is a program stored on a blockchain that automatically executes predefined actions when certain conditions are fulfilled. Unlike traditional contracts, which rely on people or institutions to enforce them, a smart contract is self-enforcing — once it’s deployed, it runs exactly as programmed without human intervention. Think of it as:“If this happens, then do that” — enforced by code and trustless infrastructure.Smart contracts are important because they eliminate the need for intermediaries, reduce the risk of fraud, and ensure agreements are executed exactly as written — with transparency and automation. This makes them a foundational building block for decentralized applications (dApps), enabling trustless interactions in finance, governance, identity, and beyond.
Analogy: A Digital Vending Machine
Imagine a vending machine:- You insert $1 and select a soda.
- The machine checks your input.
- If the condition (enough money + valid selection) is true, it dispenses the soda.
- If not, it does nothing or gives your money back.
- Input: A user sends funds or data to the contract.
- Condition: The contract checks the terms (e.g., “Has the payment been made?”).
- Action: If conditions are met, it executes the logic (e.g., transfers ownership, sends tokens).
How It Works (Technically)
- Written in code (like Solidity for Ethereum).
- Deployed to a blockchain, where it gets an address.
- Interacts with users or other contracts via transactions that other users send to its address.
- Immutable: Once deployed, you can’t alter it (unless you build upgradeable patterns).
- Transparent: Anyone can read the code and verify what it does.
Key Components of a Smart Contract
Let’s break down a simple smart contract to understand its parts:-
License and Version
// SPDX-License-Identifier: MIT
: Specifies the licensepragma solidity ^0.8.0
: Specifies the Solidity version
-
State Variables
- Variables that are permanently stored in contract storage
- Example:
uint256 private storedData
- Can be marked as
public
,private
, orinternal
-
Events
- Used to log important actions on the blockchain
- Example:
event DataStored(uint256 newValue)
- Help frontend applications track contract state changes
-
Constructor
- Runs once when the contract is deployed
- Used for initial setup
- Example:
constructor() { storedData = 0; }
-
Functions
public: Can be called by anyone
Public functions:- Can be called by anyone (external accounts, other contracts)
- Can be called by the contract itself
- Are part of the contract’s external interface
- Generate more bytecode than internal functions
- Are more gas-expensive than internal functions
- External contract interactions
- User-facing functions
- Functions that need to be called by other contracts
- Functions that implement external interfaces
private: Can only be called within the contract
Private functions:- Can only be called within the same contract
- Cannot be called by derived contracts
- Are more restrictive than internal functions
- Are gas-efficient for internal operations
- Help with code organization and security
- Internal helper functions
- Security-sensitive operations
- Functions that should never be exposed externally
- Code that should not be inherited
view: Doesn't modify state
View functions:- Can read contract state
- Cannot modify contract state
- Are gas-efficient for read operations
- Can be called without a transaction
- Can call other view functions
- Can call pure functions
- Reading contract state
- Computing values based on state
- Data validation that requires state
- Getter functions
- Status checks
pure: Doesn't read or modify state
Pure functions:- Only perform computations
- Don’t read from blockchain state
- Don’t modify blockchain state
- Are gas-efficient for read operations
- Can be called without a transaction
- Are deterministic (same input always produces same output)
- Mathematical calculations
- String manipulation
- Data validation
- Hash computations
- Any computation that doesn’t need blockchain data
Setting Up Your Development Environment
1. Install Required Tools
2. Create a New Project
3. Configure Hardhat for Nexus
Within your project directory, create/update your config filehardhat.config.js
which will define the network configuration, RPC endpoint for Hardhat to connect to, and chainID for signature verification:
4. Configure your private key in .env file
-
Get your private key from Nexus
- Go to the Nexus Web App
- Sign in to your account in the top right corner
- Click the “Settings” tab
- Navigate to “Account & Security”
- Click on “Private Key”
- Click “Reveal” to view your private key
-
Create your .env file
- Create a new file named
.env
in your project root directory - Add your private key in this format:
- Create a new file named
-
Install dotenv package
-
Update hardhat.config.js
- Add this line at the top of your
hardhat.config.js
if not already present:
- Add this line at the top of your
- Never share your private key
- Never commit it to version control
- Keep it secure and backed up
- Use a test account for development
5. Receive test NEX from a faucet for contract deployment
To deploy your contract on Nexus Layer 1, you’ll need NEX tokens to pay for gas fees. Gas fees are the cost of executing transactions on the blockchain, similar to how you need fuel to drive a car. There are two ways to receive NEX for testing:-
Earn NEX through Proving
- Submit proofs to earn points and NEX in real-time
- This is the recommended way as it helps secure the network
- For detailed instructions on proving, visit our Proving Guide
-
Use the Nexus Faucet
- A faucet is a service that provides small amounts of cryptocurrency for testing.
- It’s like a water faucet, but instead of water, it dispenses test tokens
- Visit our Faucet to receive test NEX
Writing and Deploying Your First Contract
1. Create a Contract File
Createcontracts/Lock.sol
:
This contract is the default Solidity example included when you scaffold a new Hardhat project. It demonstrates core Ethereum concepts like sending and holding ETH, working with block.timestamp
, using events, and enforcing access control with msg.sender
.
The contract implements a simple timelock wallet. When deployed, it requires:
- A future
unlockTime
(timestamp), - And an ETH payment (
payable
constructor).
owner
) can withdraw the funds. The withdraw()
function will revert if called too early or by anyone other than the owner.
This type of contract is useful for:
- Time-based escrow
- Delayed disbursements or vesting
- Testing ETH flow logic with time-based constraints
2. Create a Deployment Script
Createscripts/deploy.js
:
A deployment script is a programmatic way to deploy your smart contracts to a blockchain using Hardhat. Instead of manually interacting with the network through a UI or console, deployment scripts allow you to:
- Automate contract deployment
- Set constructor arguments dynamically
- Log or save deployed addresses
- Chain deployments in a predictable order
- Integrate easily into testing, development, or CI/CD pipelines
- It handles constructor parameters (
unlockTime
) - Manages asynchronous deployment logic with
await
- Provides helpful logs to track progress
- Prepares for contract verification (though it may be disabled or optional in some cases)
Deploying Your Contract
1. Deploy to Nexus
Run the following command to deploy your contract to the Nexus network:2. Examine Lock contract on the Nexus Explorer
Visit the Testnet III Nexus Explorer to view your deployed contract. The block explorer is a search engine for the blockchain that lets you:- View all transactions
- Check contract code
- Monitor contract interactions
- Track token transfers
- View account balances
- Copy your contract’s address from the deployment output
- Paste it into the search bar at the top of the explorer
- Click on your contract to view its details
- Contract code (verified)
- Transaction history
- Contract balance
- Recent interactions
- Event logs
Project Structure
Your project directory should look like this:contracts/
: Contains your Solidity smart contractsscripts/
: Contains deployment and interaction scripts.env
: Stores your private key and other sensitive datahardhat.config.js
: Configures your development environmentpackage.json
: Manages your project dependencies
Conclusion and Next Steps
Congratulations! You’ve successfully:- Set up your development environment
- Created and deployed your first smart contract
- Verified your contract on the Nexus Explorer
-
Learn More
- Read the Solidity Documentation
- Study OpenZeppelin Contracts, a widely-used, open-source library of secure and reusable smart contracts written in Solidity.
- Join the Nexus Discord community for:
- Frequent build events
- Developer rewards
- Technical discussions
- Community support
-
Build More
- Try deploying more complex contracts (see additional guides)
- Build a full-stack dApp