Complete guide for verifying your smart contracts on the Rayls blockchain.
- What is Contract Verification?
- Why Verify?
- Quick Start
- Verification Methods
- Configuration
- Troubleshooting
- Best Practices
Contract verification is the process of publishing your Solidity source code to a block explorer, which then compiles it and confirms that it matches the deployed bytecode on the blockchain.
Once verified:
- ✅ Anyone can read your contract's source code
- ✅ Users can interact with your contract via the block explorer UI
- ✅ The blockchain community can audit your code for security
- ✅ Your project gains trust and transparency
Users can see exactly what your contract does before interacting with it.
The community can audit your code for vulnerabilities and best practices.
Block explorers provide a web interface to read/write to verified contracts without writing code.
All professional blockchain projects verify their contracts. It's expected by users and investors.
npm run deploy:verifyThis deploys your contract and automatically verifies it on the block explorer.
If you already deployed your contract:
-
Edit
scripts/verify.tsand replace the contract address:const contractAddress = "0xYourActualContractAddress";
-
Run verification:
npm run verify
npx hardhat verify --network rayls <CONTRACT_ADDRESS> "<CONSTRUCTOR_ARGS>"Example for RaylsToken:
npx hardhat verify --network rayls 0xYourAddress "1000000000000000000000000"File: scripts/deploy-and-verify.ts
This script:
- Deploys your contract
- Waits for 5 block confirmations
- Automatically verifies on the block explorer
- Handles errors gracefully
Run:
npm run deploy:verifyFeatures:
- Automatic error handling
- Clear progress messages
- Fallback manual verification command on failure
- Complete deployment + verification in one command
File: scripts/verify.ts
Use this when you've already deployed and want to verify later.
Steps:
- Update contract address in
scripts/verify.ts - Ensure constructor arguments match deployment
- Run:
npm run verify
For quick verifications without scripts:
npx hardhat verify --network rayls \
--contract contracts/RaylsToken.sol:RaylsToken \
0xYourContractAddress \
"1000000000000000000000000"When to use:
- Quick one-off verifications
- Testing verification setup
- When scripts don't work
If automated verification fails, use manual verification via the block explorer:
Step 1: Flatten the contract
npm run flattenThis creates RaylsToken-flattened.sol with all dependencies in one file.
Step 2: Clean up the flattened file
- Open
RaylsToken-flattened.sol - Remove duplicate SPDX license identifiers (keep only the first one)
- Save the file
Step 3: Manual verification on block explorer
- Go to the Rayls block explorer
- Find your contract address
- Click "Verify & Publish" (or similar)
- Fill in the form:
- Compiler version:
0.8.20 - Optimization:
Enabled - Runs:
200 - Paste the flattened source code
- Enter constructor arguments (ABI-encoded)
- Compiler version:
Constructor Arguments Encoding:
For 1,000,000 tokens (1M × 10^18):
0x00000000000000000000000000000000000000000000d3c21bcecceda1000000
To get ABI-encoded constructor arguments:
import { ethers } from "hardhat";
const initialSupply = ethers.parseUnits("1000000", 18);
console.log(initialSupply.toString()); // Raw valueAdd to your .env file:
PRIVATE_KEY=0xYourPrivateKeyYour hardhat.config.ts should include:
etherscan: {
apiKey: {
rayls: "no-api-key-needed",
},
customChains: [
{
network: "rayls",
chainId: 123123, // Must match your network config
urls: {
apiURL: "https://devnet-explorer.rayls.com/api",
browserURL: "https://devnet-explorer.rayls.com"
}
}
]
}Note: Rayls block explorer does not require an API key for contract verification.
Cause: Contract is already verified on the explorer.
Solution: This is actually success! Check the block explorer to confirm.
Cause: The arguments you provided don't match what was used during deployment.
Solution:
- Find your deployment transaction on the block explorer
- Check the input data to see constructor arguments
- Use the exact same values for verification
For RaylsToken Example:
- If you deployed with 1M tokens:
"1000000000000000000000000" - If you deployed with 5M tokens:
"5000000000000000000000000000"
Helper to get correct format:
import { ethers } from "hardhat";
const supply = ethers.parseUnits("1000000", 18);
console.log(supply.toString()); // Use this valueCause: The Solidity compiler version doesn't match.
Solution:
- Check
hardhat.config.ts→solidity.version - Use the exact version:
0.8.20(not^0.8.20or0.8.x) - Ensure the version matches what was used during compilation
Cause: Optimizer settings don't match deployment.
Solution:
Check your hardhat.config.ts:
optimizer: {
enabled: true, // Must match
runs: 200, // Must match
}Use these same settings when verifying manually.
Cause: The verification plugin doesn't recognize the network.
Solution:
Ensure customChains is configured in hardhat.config.ts:
customChains: [
{
network: "rayls",
chainId: 123123, // Must match networks.rayls.chainId
urls: {
apiURL: "https://explorer.rayls.com/api",
browserURL: "https://explorer.rayls.com"
}
}
]Cause: Cannot connect to the block explorer API.
Solution:
- Verify the explorer URLs are correct
- Check if the explorer is operational
- Try again after a few minutes
- Verify your internet connection
Cause: Contract address doesn't exist or isn't deployed yet.
Solution:
- Verify the contract address is correct
- Check the transaction was confirmed on-chain
- Wait a few more blocks and try again
- Ensure you're using the correct network
Don't wait! Verify right after deploying while you have all the information fresh.
npm run deploy:verify # Deploy and verify togetherKeep a record of what arguments you used:
// deployment-log.txt
Contract: RaylsToken
Address: 0xabcd...
Initial Supply: 1000000 tokens (1000000000000000000000000 wei)
Deployer: 0x1234...
Timestamp: 2025-01-15 10:30:00
Network: Rayls DevnetAlways deploy and verify on testnet before mainnet:
- Verify the process works
- Confirm explorer URLs are correct
- Test the complete verification flow
Avoid manual commands when possible:
- Less prone to human error
- Easier to reproduce
- Better for CI/CD pipelines
Never change hardhat.config.ts after deployment:
- Compiler version
- Optimization settings
- Any other compilation settings
Always include a license identifier in your contracts:
// SPDX-License-Identifier: MITThis tells users how they can use your code.
If you deploy multiple contracts, verify them all:
- Token contracts
- Factory contracts
- Proxy contracts
- Implementation contracts (for upgradeable contracts)
After successful verification, save the block explorer URL:
https://explorer.rayls.com/address/0xYourContractAddress
Share this with your users and community.
If you have multiple contracts in one file:
npx hardhat verify --network rayls \
--contract contracts/RaylsToken.sol:RaylsToken \
0xAddress \
"args"npx hardhat verify --list-networksVisit your contract on the block explorer:
https://explorer.rayls.com/address/0xYourContractAddress
Look for:
- ✅ Green checkmark = Verified
- ❌ No checkmark = Not verified
Quick Verification:
# Deploy and verify in one command
npm run deploy:verify
# Or verify existing contract
npm run verify # After editing scripts/verify.tsManual Verification:
# Flatten contract
npm run flatten
# Upload RaylsToken-flattened.sol to block explorerVerification Checklist:
- Contract is deployed and confirmed
- Explorer URLs are correct in config
- Constructor arguments are documented
- Compiler version matches
- Optimization settings match
- Hardhat Verification Plugin
- Etherscan Verification Guide
- Rayls Documentation (check for explorer-specific instructions)
Questions? Check the main README.md or Troubleshooting section.