Skip to main content

Hydrix Chain — Smart Contracts

Hydrix Chain is EVM-compatible, fully supporting Solidity contracts and Ethereum tooling.
This section focuses on advanced deployment, interactions, and best practices for developers.

Contract Standards​

  • Solidity version: ^0.8.20
  • EVM-compatible: Yes (Polygon Edge–based)
  • Gas token: HYX, 1 gwei base price
  • Supports all standard Ethereum JSON-RPC calls
  • Use OpenZeppelin libraries for ERC20, ERC721, access control, and multisig contracts
  • Keep gas usage minimal for PoA validators
  • Include events for contract monitoring and off-chain indexing

Deploying Contracts with Failover​

Developers should handle validator failover when deploying or interacting with contracts:

import { ethers } from "ethers";

const validators = [
"https://chainfree.info:5010/validator/1",
"https://chainfree.info:5010/validator/2",
"https://chainfree.info:5010/validator/3",
"https://chainfree.info:5010/validator/4"
];

async function deployContract(contractName, walletPrivateKey) {
let deployed;
for (let i = 0; i < validators.length; i++) {
try {
const provider = new ethers.JsonRpcProvider(validators[i]);
const wallet = new ethers.Wallet(walletPrivateKey, provider);
const factory = await ethers.getContractFactory(contractName, wallet);
deployed = await factory.deploy();
await deployed.waitForDeployment();
console.log(`Deployed on Validator ${i + 1}:`, deployed.target);
break;
} catch (err) {
console.warn(`Validator ${i + 1} failed, trying next...`);
}
}
if (!deployed) throw new Error("All validators failed");
return deployed;
}

Interacting with Deployed Contracts​

Use Ethers.js or Web3.js to call and send transactions:

const provider = new ethers.JsonRpcProvider("https://chainfree.info:8545");
const wallet = new ethers.Wallet("YOUR_PRIVATE_KEY", provider);
const contractAddress = "DEPLOYED_CONTRACT_ADDRESS";
const abi = [
"function message() view returns (string)",
"function setMessage(string calldata)"
];
const contract = new ethers.Contract(contractAddress, abi, wallet);

// Read state
const currentMessage = await contract.message();
console.log("Current message:", currentMessage);

// Update state
const tx = await contract.setMessage("New message on Hydrix");
await tx.wait();
console.log("Message updated!");

Advanced Topics​

  • Event monitoring: Capture and index events using contract.on("EventName", handler)
  • Gas optimization: Minimize storage writes; batch operations where possible
  • Multisig contracts: Use OpenZeppelin Ownable or Gnosis Safe patterns
  • Contract upgrades: Proxy patterns supported, standard EVM methods

Security Best Practices​

  • Test all contracts on the Hydrix testnet before mainnet deployment
  • Keep private keys and sensitive operations off-chain where possible
  • Monitor validator health; switch RPC endpoints if latency spikes occur
  • Review code using automated tools and audits

Next Steps​

Once contracts are deployed:

  • Integrate with dApps via Hydrix RPC endpoints
  • Use lightweight nodes for read-heavy applications
  • Monitor events and logs for application state tracking