Perfect—local blockchain is the way to go for testing and iterating without burning real ETH. Here’s a quick game plan to get your **RaysCoin referral logic** working on a local chain like [Ganache](https://trufflesuite.com/ganache/) or [Hardhat](https://hardhat.org/):
—
### 🔧 1. **Set Up Your Environment**
– **Install Node.js** and then install Hardhat:
“`bash
npm install –save-dev hardhat
“`
– Initialize a Hardhat project:
“`bash
npx hardhat
“`
Choose “Create a basic sample project” when prompted.
—
### 📜 2. **Write the Smart Contract (`RaysCoin.sol`)**
Here’s a lean version of your logic:
“`solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;
contract RaysCoin is ERC20 {
mapping(address => bool) public hasJoined;
mapping(address => address) public referrer;
constructor() ERC20(“RaysCoin”, “RAY”) {}
function join(address _referrer) public {
require(!hasJoined[msg.sender], “Already joined”);
hasJoined[msg.sender] = true;
if (_referrer != address(0) && hasJoined[_referrer]) { referrer[msg.sender] = _referrer;
_mint(_referrer, 100 * 1e18);
}
_mint(msg.sender, 100 * 1e18);
}
}
“`
You can drop this into `contracts/RaysCoin.sol`.
—
### 🧪 3. **Deploy to Local Network**
In `scripts/deploy.js`:
“`js
const hre = require(“hardhat”);
async function main() {
const RaysCoin = await hre.ethers.getContractFactory(“RaysCoin”); const rays = await RaysCoin.deploy();
await rays.deployed();
console.log(“RaysCoin deployed to:”, rays.address);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
“`
Then run:
“`bash
npx hardhat node # start local blockchain
npx hardhat run scripts/deploy.js –network localhost
“`
—
### 🛠️ 4. **Test the Logic**
Use Hardhat console or write a test like:
“`js
await rays.join(referrerAddress); // New member joins
await rays.join(anotherReferrer); // Next member joins with referral “`
You’ll see minting occur per your logic.
—
Once you’re happy with it, I can help you deploy to Sepolia testnet or embed this logic into your front-end PWA or Telegram Mini App. Want me to help scaffold a test UI next? We could hook it into your existing ecosystem lightning fast. ⚡ Sent from my iPhone