Deploy Smart Contracts on KUB
This walkthrough helps you set up your environment, deploy a smart contract to KUB Testnet, and verify it on KUB Scan.
What You'll Achieve
By the end of this quickstart, you'll be able to:
Set up your development environment to deploy on the KUB Testnet
Deploy your smart contracts to the KUB Testnet
Verify your contract on KUB Scan
Set Up Your Development Environment
Create a new project directory
mkdir my-kub-project && cd my-kub-projectInstall Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryupIf curl | bash installs are blocked in your environment; install via Homebrew instead: brew install foundry.
Initialize a new Solidity project
forge initYour Foundry project is now ready. You'll find an example contract below, which we'll use for the rest of this guide.
Configure Foundry with KUB
To deploy to the KUB network, you need three things: an EVM version setting, a node connection, and a funded private key.
Target the correct EVM version
The KUB EVM predates the Shanghai upgrade, so it rejects the PUSH0 opcode that solc 0.8.20 and later emit by default. Without this setting, deployment fails with the cryptic error invalid opcode: opcode 0x5f not defined. Add the following to your foundry.toml under [profile.default]:
This compiles your contracts without PUSH0 while keeping the latest Solidity language features. It applies to every forge command in this guide, including verification, so the verified bytecode matches what you deployed.
Set up your node connection
Create a .env file in your project root
Load your environment variables
KUB Testnet is the test network we'll use for the rest of this guide. Get free tKUB from the KUB Faucet; it dispenses 5 tKUB to your address every 24 hours. If you wish to deploy to other KUB networks, refer to this guide.
Secure your private key
Store your private key in Foundry's encrypted keystore
When prompted, enter your private key and a password. The key is stored in ~/.foundry/keystores, which is not tracked by git.
Never share or commit your private key. Always keep it secure and handle it with care.
Deploy Your Contracts
Compile and deploy the Counter contract to the KUB Testnet
The --legacy flag is required. KUB does not support EIP-1559 fee estimation, so forge create without it fails with "Failed to estimate EIP1559 fees". --legacy sends a pre-EIP-1559 transaction with a plain gas price instead.
After a successful deployment, the transaction hash and contract address are printed to the console. Add the address to your .env
Reload the environment
Verify Your Deployment
Check the transaction on KUB Testnet and read the initial counter value from the command line
This should return 0, the initial value of the Counter's number storage variable.
Verify the Source Code on KUB Scan
Verify the source code on KUB Scan with Foundry using the following command line
For KUB Mainnet, swap the verifier URL to https://www.kubscan.com/api.
The KUB Scan API enforces a rate limit of 12 requests per minute per IP. Exceeding it blocks the IP for 1 minute.
Congratulations! You've deployed and verified a smart contract on KUB Testnet.
Next Steps
Launch a token with the KAP standard (see this guide).
Submit your app to the KUB Developer Center to be showcased in the KUB Ecosystem.
Last updated