@smartforge/contracts
v1.0.1
Published
Smart contract templates and compilation utilities for Contract Studio.
Readme
@smartforge/contracts
Smart contract templates and compilation utilities for Contract Studio.
Installation
npm install @smartforge/contracts
# or
pnpm add @smartforge/contractsUsage
Get Contract Templates
import { getAllTemplates, getTemplate } from "@smartforge/contracts";
// Get all available templates
const templates = getAllTemplates();
console.log(templates); // ERC20, ERC721, etc.
// Get specific template
const erc20Template = getTemplate("erc20");
if (erc20Template) {
console.log(erc20Template.name); // "ERC20 Token"
console.log(erc20Template.baseCode); // Solidity code
}Validate Contract Code
import { validateContractCode } from "@smartforge/contracts";
const validation = validateContractCode(sourceCode);
if (validation.valid) {
console.log("Contract code is valid");
} else {
console.error("Errors:", validation.errors);
}Compile Contract
import { compileContract } from "@smartforge/contracts";
const result = await compileContract({
sourceCode: solidityCode,
contractName: "MyContract",
optimize: true,
optimizerRuns: 200,
});
if (result.success) {
console.log("ABI:", result.abi);
console.log("Bytecode:", result.bytecode);
} else {
console.error("Compilation errors:", result.errors);
}Estimate Gas
import { estimateGas } from "@smartforge/contracts";
const estimate = await estimateGas(
"0x...", // contract address
"mint", // function name
[to, amount], // function arguments
8453 // chain ID
);
if (estimate.success) {
console.log("Gas estimate:", estimate.gasEstimate?.toString());
}Available Templates
ERC20 Token
Template ID: erc20
Standard fungible token with:
- Transfer functionality
- Approval/allowance system
- Customizable name, symbol, decimals, initial supply
ERC721 NFT
Template ID: erc721
Non-fungible token with:
- Minting functionality
- Transfer functionality
- Owner controls
- Pausable functionality
API
Template Functions
getAllTemplates()- Get all available templatesgetTemplate(id)- Get template by ID
Compiler Functions
compileContract()- Compile Solidity contract (stub)validateContractCode()- Validate contract syntaxestimateGas()- Estimate gas for function call (stub)
Template Structure
interface ContractTemplate {
id: string;
name: string;
description: string;
category: "nft" | "token" | "marketplace" | "custom";
blocks: ContractBlock[];
baseCode: string;
}License
ISC
