Best Practices

Security

Input Validation

Utils.assert(Utils.addressCheck(to), 'Invalid address');
Utils.assert(Utils.stoI256Check(amount), 'Invalid amount');
Utils.assert(Utils.int256Compare(amount, '0') > 0, 'Amount must be positive');

Access Control

const owner = Chain.load('owner');
Utils.assert(Chain.msg.sender === owner, 'Only owner');

Reentrancy Protection

Utils.assert(!Chain.load('locked'), 'Reentrant call');
Chain.store('locked', 'true');
// ... operations ...
Chain.store('locked', 'false');

Gas Optimization

Minimize Storage

Use Local Variables


Code Organization

Separate Concerns

Clear Error Messages

Event Logging


Last updated