In the deep, blocky jungles of Ethereum, where gas fees climb like mountain goats and Solidity developers communicate in ABI code, a strange phenomenon has emerged: self-replicating smart contracts, also known as quines.
What is a quine? In computer science, it’s a program that prints its own source code. In blockchain land, it's the “Look Ma, I deployed myself!” of the smart contract world.
These little devils stare into the void of the Ethereum Virtual Machine and boldly ask:
“What if I… deployed… me… again?”
If you think smart contracts were getting a bit too serious, well, hold your dev hats. Today, we’re going to laugh, cry (when we see the gas bill), and write two quines—one serious, one silly.
Quines are useless. Utterly. Beautifully. Useless.
They have no business model, no killer dApp status, and probably no VC funding.
They’re the NFT equivalent of a smart contract looking into a mirror and going: "Wow. Perfection."
But they’re also a beautiful way to explore recursion, deployment logic, and the narcissistic tendencies of code left unsupervised.
This quine deploys a clone of itself. It literally re-deploys its own source code on the blockchain.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SolidityQuine {
event Deployed(address clone);
function deployClone() public {
bytes memory source = hex"6080604052348015600f57600080fd5b5060..."; // full bytecode of this contract
address addr;
assembly {
addr := create(0, add(source, 0x20), mload(source))
}
emit Deployed(addr);
}
}
Note: To make this work, you need to paste the actual bytecode of the contract into the source variable. This is like a snake swallowing itself and somehow producing another snake. Don’t overthink it.
Note: To make this work, you need to paste the actual bytecode of the contract into the source
variable. This is like a snake swallowing itself and somehow producing another snake. Don’t overthink it.
Gas Estimate: Somewhere between “Ouch” and “WHY DID I DO THIS?”
This contract doesn’t just replicate—it has a crisis every time it does.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract QuineExistential {
string public lastWords;
address public latestClone;
event Birth(address babyClone, string lastWords);
constructor(string memory _lastWords) {
lastWords = _lastWords;
}
function replicate() public {
string memory newWords = string(abi.encodePacked("Am I still me? ", lastWords));
bytes memory bytecode = abi.encodePacked(
type(QuineExistential).creationCode,
abi.encode(newWords)
);
address clone;
assembly {
clone := create(0, add(bytecode, 0x20), mload(bytecode))
}
latestClone = clone;
emit Birth(clone, newWords);
}
}
Imagine a contract that replicates, and the clone calls replicate again, and again...
Ethereum: "I'm gonna stop you right there."
Gas fees: "Heh. Hehehe. CHA-CHING."
Quines are the blockchain's version of performance art. They ask no permission, offer no value, but deliver pure, elegant weirdness.
So next time you’re stuck writing another DEX, NFT marketplace, or yield-optimized banana farm, take a moment and write a quine. Let your smart contracts love themselves a little.
After all, in the end, don’t we all just want to deploy our true selves?
⚠️ Disclaimer: Deploying quines for fun is fine. Deploying quines for profit is… well, a good way to find out what “audit” really means.