create2
wednesday-ui/create2FreeUtility
Wednesday UI publishes no description for this item.
Install it
npx shadcn@latest add https://ui.ednesdayw.com/r/create2.jsonSource
1import { createHash } from "crypto";2import bs58 from "bs58";3import { keccak256 } from "js-sha3";4import { isEVMAddress, isTronAddress } from "./wallet-address";56// ============ Types ============7interface Create2PredictAddressParams {8 implementation: string;9 deployer: string;10 salt: string;11}1213// ============ Constants ============14// EIP-1167 Minimal Proxy Bytecode15const MINIMAL_PROXY = {16 PREFIX: "3d602d80600a3d3981f3363d3d373d3d3d363d73",17 EVM_SUFFIX: "5af43d82803e903d91602b57fd5bf3ff",18 TRON_SUFFIX: "5af43d82803e903d91602b57fd5bf341",19} as const;2021// Bytecode Processing22const BYTECODE_CONFIG = {23 FIRST_PART_END: 110,24 SECOND_PART_END: 280,25 ADDRESS_SIZE: 40,26} as const;2728// ============ Main Functions ============2930/**31 * Predicts the deterministic address for a contract using CREATE232 */33export function create2(34 data: Create2PredictAddressParams & { network?: "evm" | "tron" },35) {36 const { implementation, deployer, salt, network = "evm" } = data;37 if (network === "evm") {38 return predictDeterministicEVMAddress({ implementation, deployer, salt });39 }40 return predictDeterministicTronAddress({ implementation, deployer, salt });41}4243/**44 * Predicts the deterministic address for an EVM contract using CREATE245 */46export function predictDeterministicEVMAddress({47 implementation,48 deployer,49 salt,50}: Create2PredictAddressParams): string {51 // Validate inputs52 validateEVMAddress(implementation, "implementation");53 validateEVMAddress(deployer, "deployer");54 validateSalt(salt);5556 // Prepare parameters57 const saltHex = stringToHex(salt, 32);58 const cleanImplementation = removeHexPrefix(implementation);59 const cleanDeployer = removeHexPrefix(deployer);6061 // Build bytecode62 const bytecode = buildBytecode(63 cleanImplementation,64 cleanDeployer,65 saltHex,66 MINIMAL_PROXY.EVM_SUFFIX,67 );6869 // Calculate address70 const addressHex = calculateAddressFromBytecode(bytecode);71 return toChecksumAddress(`0x${addressHex}`);72}7374/**75 * Predicts the deterministic address for a TRON contract using CREATE276 */77export function predictDeterministicTronAddress({78 implementation,79 deployer,80 salt,81}: Create2PredictAddressParams): string {82 // Validate inputs83 validateTronAddress(implementation, "implementation");84 validateTronAddress(deployer, "deployer");85 validateSalt(salt);8687 // Prepare parameters88 const saltHex = stringToHex(salt, 32);89 const cleanImplementation = tronAddressToHex(implementation);90// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Wednesday UI
All 99 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| colorscolors | Wednesday UI | Utilities | Free | no deps | |
| paginatepaginate | Wednesday UI | Utilities | Free | no deps | |
| utilsutils | Wednesday UI | Utilities | Free | 2 deps | |
| wallet-addresswallet-address | Wednesday UI | Utilities | Free | 1 dep |
