@ghostchain1/hardhat-ghost
v0.0.2
Published
Hardhat plugin — injects the Ghost SDK namespace into the Hardhat Runtime Environment
Downloads
437
Maintainers
Readme
@ghostchain1/hardhat-ghost
Hardhat plugin that injects the Ghost SDK namespace (hre.ghost) into the Hardhat Runtime Environment, replacing the raw hre.ethers surface with Ghost-branded helpers.
Install
npm install @ghostchain1/hardhat-ghost
# or
pnpm add @ghostchain1/hardhat-ghostConfigure the registry for GitHub Package Registry:
# .npmrc
@ghostchain:registry=https://npm.pkg.github.comSetup
In hardhat.config.ts, load @nomicfoundation/hardhat-ethers first, then this plugin:
import "@nomicfoundation/hardhat-ethers"; // must come first
import "@ghostchain1/hardhat-ghost";Usage
import { ghost } from "hardhat";
async function main() {
const [deployer] = await ghost.getSigners();
// Deploy a contract
const factory = await ghost.getContractFactory("GhostToken");
const token = await factory.deploy();
await token.waitForDeployment();
// Parse / format Ghost amounts
const oneGST = ghost.parseGhost("1.0"); // 1e18n
console.log(ghost.formatGhost(oneGST)); // "1.0"
// Utilities
const addr = ghost.getAddress("0xabc...");
const hash = ghost.keccak256(ghost.toUtf8Bytes("hello"));
const hex = ghost.toBeHex(255n); // "0xff"
}hre.ghost API
Signers & Contracts
| Method | Description |
|---|---|
| ghost.getSigners() | Returns all unlocked test node signers |
| ghost.getSigner(address) | Returns a specific signer by address |
| ghost.getContractFactory(name, signer?) | Deploy-ready factory for a named artifact |
| ghost.getContractFactoryFromArtifact(artifact, signer?) | Factory from raw ABI + bytecode |
| ghost.getContractAt(name, address, signer?) | Attach to a deployed contract |
| ghost.getContract(name, address, signer?) | Alias for getContractAt |
Ghost Unit Helpers
| Property / Method | Description |
|---|---|
| ghost.parseGhost(value) | Parse a human-readable GST string to GhostWei (bigint) |
| ghost.formatGhost(value) | Format GhostWei to a GST string |
| ghost.parseGhostGwei(value) | Parse GhostGwei string to GhostWei |
| ghost.formatGhostGwei(value) | Format GhostWei to GhostGwei string |
| ghost.parseEther(value) | ethers parseEther |
| ghost.parseUnits(value, unit?) | ethers parseUnits |
| ghost.units | { GhostWei, GhostGwei, GhostOne } constants |
Gas
| Property | Description |
|---|---|
| ghost.GasEngine | GhostGasEngine class — getFeeData(), estimateGas(tx) |
Classes
| Property | Description |
|---|---|
| ghost.Contract | ethers Contract class |
| ghost.ContractFactory | ethers ContractFactory class |
| ghost.Interface | ethers Interface class |
| ghost.AbiCoder | ethers AbiCoder class |
| ghost.TypedDataEncoder | ethers TypedDataEncoder class |
| ghost.JsonRpcProvider | GhostJsonRpcProvider — L1/L2/L3-aware provider |
| ghost.Wallet | GhostWallet |
Utilities
| Property | Description |
|---|---|
| ghost.getAddress(addr) | Checksum an address |
| ghost.getCreateAddress(addr, nonce) | Derive a CREATE contract address |
| ghost.isAddress(value) | Type guard for addresses |
| ghost.isHexString(value, length?) | Type guard for hex strings |
| ghost.keccak256(data) | keccak256 hash |
| ghost.id(text) | keccak256 of a UTF-8 string |
| ghost.solidityPacked(types, values) | ABI-packed encoding |
| ghost.toBeHex(value, width?) | Convert bigint to hex string |
| ghost.toUtf8Bytes(text) | Encode a string as UTF-8 bytes |
| ghost.zeroPadValue(value, length) | Zero-pad a hex value to length bytes |
| ghost.dataSlice(data, start?, end?) | Slice hex data |
Constants
| Property | Value |
|---|---|
| ghost.ZeroAddress | "0x0000000000000000000000000000000000000000" |
| ghost.ZeroHash | "0x0000...0000" (32 bytes) |
| ghost.MaxUint256 | 2n ** 256n - 1n |
Network
| Property | Description |
|---|---|
| ghost.Networks | GhostNetworks — L1/L2/L3 network configs |
| ghost.provider | Hardhat network provider |
ghost:generate Task
Generate a GhostChain Solidity contract from a template:
npx hardhat ghost:generate --type token --name GhostGovToken --symbol GGT
npx hardhat ghost:generate --type nft --name GhostBadge --symbol GBDG
npx hardhat ghost:generate --type staking --name MyStaking
npx hardhat ghost:generate --type dao --name MyCouncil
npx hardhat ghost:generate --type dex --name GhostX --no-deployOptions:
| Flag | Default | Description |
|---|---|---|
| --type | (required) | token | nft | staking | dao | dex |
| --name | (required) | PascalCase contract name |
| --symbol | "" | Token/NFT symbol (for token and nft types) |
| --out-dir | generated | Output subdirectory under contracts/src/ |
| --max-supply | "" | Max total supply for token type |
| --no-deploy | false | Skip generating a Hardhat deploy script |
| --emit-sdk | false | Also emit a TypeScript SDK wrapper stub |
Requires @ghostchain1/ghost-contract-factory (optional peer dependency):
pnpm add @ghostchain1/ghost-contract-factoryLicense
MIT © GhostChain Team
