A JavaScript utility for deterministic smart contract address prediction using CREATE2, supporting both EVM and Tron (TVM) networks.
Installation
pnpm dlx shadcn@latest add "https://ui.ednesdayw.com/r/create2.json"
Usage
import {
create2,
predictDeterministicEVMAddress,
predictDeterministicTronAddress,
} from "@/lib/create2";
// Predict an EVM contract address (default)
const evmAddress = create2({
implementation: "0x47deB22A87D12c8BE5F638AFC7DE48b52968205b",
deployer: "0x6a569215be90A55B4c615368fCB13F75d99c8A60",
salt: "my-unique-salt",
});
// Predict a TRON contract address
const tronAddress = create2({
implementation: "TL2ScqgY9ckK5h1VQExuMNrweyVSSdAtHa",
deployer: "TFgphAx29XEwrS8feFMpPfqzypjYzNysSH",
salt: "my-unique-salt",
network: "tron",
});
console.log(evmAddress); // Output: 0x... (predicted EVM contract address)
console.log(tronAddress); // Output: T... (predicted TRON contract address)
API
create2
Universal function for predicting deterministic addresses for contracts using CREATE2 with minimal proxy pattern (EIP-1167).
create2(params: Create2PredictAddressParams & { network?: "evm" | "tron" }): string
Parameters
params
- An object containing:implementation
- The implementation contract address (EVM:0x...
, TRON:T...
)deployer
- The deployer contract address (EVM:0x...
, TRON:T...
)salt
- A unique string salt (max 32 characters) used for address generationnetwork
- (Optional) Network type:"evm"
(default) or"tron"
Returns
string
- Returns the predicted deterministic contract address.
predictDeterministicEVMAddress
Predicts the deterministic address for an EVM contract using CREATE2.
predictDeterministicEVMAddress(params: Create2PredictAddressParams): string
Parameters
params
- An object containing:implementation
- The implementation contract address (0x${string}
)deployer
- The deployer contract address (0x${string}
)salt
- A unique string salt (max 32 characters) used for address generation
Returns
string
- Returns the predicted EVM contract address with checksum.
predictDeterministicTronAddress
Predicts the deterministic address for a TRON contract using CREATE2.
predictDeterministicTronAddress(params: Create2PredictAddressParams): string
Parameters
params
- An object containing:implementation
- The implementation contract address (Base58 format starting withT
)deployer
- The deployer contract address (Base58 format starting withT
)salt
- A unique string salt (max 32 characters) used for address generation
Returns
string
- Returns the predicted TRON contract address in Base58 format.
Errors
- Throws if the implementation address is invalid
- Throws if the deployer address is invalid
- Throws if the salt exceeds 32 characters
Validation Functions
isValidEVMAddress
Validates an EVM address format.
isValidEVMAddress(address: string): boolean
isValidTronAddress
Validates a TRON address format.
isValidTronAddress(address: string): boolean
How it works
This utility implements the CREATE2 address prediction algorithm using the minimal proxy pattern (EIP-1167). The minimal proxy is a standardized bytecode pattern that delegates all calls to an implementation contract, allowing for gas-efficient contract deployments.
The address is calculated by:
- Constructing the minimal proxy bytecode with the implementation address
- Combining it with the deployer address and salt
- Computing the keccak256 hash of the encoded parameters
- Extracting the last 20 bytes as the predicted address
Network Support:
- EVM Networks: Uses standard Ethereum address format (0x prefix, 42 characters)
- TRON Network: Uses Base58 encoding with T prefix (34 characters)