A step-by-step tutorial to deploy and register your first contract on BattleChain
This tutorial walks you through deploying a contract to BattleChain and getting it ready for stress testing. By the end, you’ll have a contract in attack mode, open for whitehats to test.
Prerequisites: You should have an audited smart contract ready to deploy and some test funds for liquidity.
The recommended way to deploy is through BattleChainDeployer, which automatically registers your contract with the AttackRegistry.
Copy
// Get the BattleChainDeployer instanceBattleChainDeployer deployer = BattleChainDeployer(BATTLECHAIN_DEPLOYER_ADDRESS);// Deploy your contract using CREATE2 for deterministic addressesbytes memory bytecode = type(MyVault).creationCode;bytes32 salt = keccak256("my-vault-v1");address myVault = deployer.deployCreate2(salt, bytecode);// myVault is now registered with AttackRegistry
Your contract is now deployed and registered. You (the deployer) are automatically authorized to request attack mode.
Already deployed without BattleChainDeployer?
If your contract was deployed through other means, you can still request attack mode using requestUnderAttackByNonAuthorized. This function allows any contract to enter the attack flow, but requires DAO approval like normal.In Step 5, use this instead:
IAttackRegistry.ContractState state = attackRegistry.getAgreementState(agreement);// ATTACK_REQUESTED (2) = waiting for approval// UNDER_ATTACK (3) = approved! Whitehats can now attack