AssetContract is an ERC721A-based soulbound token smart contract for managing asset data records on-chain. It allows issuance, verification, redemption, and extension of data entries, ensuring uniqueness and immutability of asset records.
- Solidity version: ^0.8.24
- Inherits: ERC721A, Ownable
- Errors:
DataNotExistDataAlreadyExistsInvalidTokenIdDataAlreadyRedeemedDataExpiredTransferNotAllowedTokenNotExistsDocumentNotApprovedDocumentAlreadyApprovedUnauthorized
- Events:
DataIssued(uint256 indexed tokenId, address issuer, bytes32 dataHash, bytes32 docType, uint256 createdDated)SetDataURL(uint256 indexed tokenId, string onChainUrl)DataValidated(bytes32 dataHash, bool isValid)Redeemed(uint256 tokenId, address redeemedBy)DataExtended(bytes32 indexed dataHash, uint256 indexed extendDate)DocumentApproved(bytes32 indexed docTypeHash)
- Core Functions:
approveDocType(string docType)setApproveClient(address client, bool status)mintData(bytes32 dataHash, bytes32 docType, string assetData)verifyData(bytes32 dataHash, bytes32 docType)setOnChainURL(bytes32 dataHash, bytes32 docType, string url)redeemData(bytes32 dataHash, bytes32 docType)getAssetData(bytes32 dataHash, bytes32 docType) returns (Data)getDateMintingData(bytes32 dataHash, bytes32 docType) returns (uint256)
- Soulbound Behavior: Overrides transfer and approval functions to prevent transfers after minting. Token IDs start at 1.
- Node.js >= 16.x
- Yarn >= 4.x
- Hardhat
- Ethers.js & TypeChain
git clone <your-repo-url>
cd <name-folder>
yarn install- Compile:
yarn compile - Test:
yarn test - Coverage:
yarn coverage(if solidity-coverage configured) - Gas Report:
REPORT_GAS=1 yarn test-gas - Deploy:
yarn deploy
hardhat-boilerplate/
├── contracts/ # Solidity smart contracts
│ └── AssetContract.sol
├── config/ # Configuration files (CollectionConfig, ContractArguments)
├── lib/ # NftContractProvider
├── scripts/ # Deployment & setup scripts
├── test/ # Unit tests
├── .env # Environment variables
├── hardhat.config.ts # Hardhat configuration
├── package.json
└── README.md
Approves a new document type. Access: Only owner.
Sets approval status for a client address. Access: Only owner.
Mints a new soulbound token with associated asset data.
- Reverts:
DataAlreadyExists,DocumentNotApproved
Validates a data entry. Emits DataValidated on success.
- Reverts:
DataAlreadyRedeemed,DataExpired,DataNotExist
Sets the on-chain URL for an existing data entry.
- Access: Only approved clients.
Redeems a data entry, updating its status to Redeemed.
- Affects: Emits
Redeemed - Reverts:
DataAlreadyRedeemed,DataExpired,DataNotExist
Retrieves full data details for a given hash.
Returns the timestamp when the data was created.
- Reverts:
DataNotExist,InvalidTokenId
- Fork the repository and create a feature branch:
git checkout -b feat/your-feature - Commit your changes with clear, semantic messages:
git commit -m "feat: add ..." - Push to your fork:
git push origin feat/your-feature - Open a Pull Request describing your changes.
Code Style: Use Prettier for formatting and write tests for new functionality.
- Node.js (v14 or higher)
- Yarn package manager
- Hardhat installed in your project (
npm install --save-dev hardhat) - Your project’s
package.jsonmust define the following scripts:deploy-localhostsetup-clientsetup-doctype
- You can adding
Minter Rolewith adding new lines inscripts/3_setup_client.ts. - You can adding
Doc Typewith modified or adding new line inscripts/4_setup_docType.ts.
This script will:
-
Launch a Hardhat local node in the background.
-
Wait until the node is ready on port
8545. -
Run the following Yarn commands in sequence:
yarn deploy-localhost yarn setup-client --network localhost yarn setup-doctype --network localhost
-
Keep the node running until you terminate the script.
-
Automatically clean up (kill the Hardhat node) when you press
Ctrl+Cor when the script receives a termination signal.
- Automatic readiness check: Ensures commands run only after the node is up.
- Signal trapping: Gracefully shuts down the Hardhat node on
SIGINT/SIGTERM. - Customizable: Easily modify the Yarn commands or network settings as needed.
-
Make the script executable:
chmod +x deploy-local.sh
-
Run the script:
./deploy-local.sh
-
Once all steps finish, your local node will continue running. Press
Ctrl+Cto stop everything.
- Modify client: If you want setup another minter please add new line in
scripts/3_setup_client.ts. - Modify doc: If you want setup another doc please add new line in
scripts/4_setup_docType.ts. - Adjust commands: Swap or append Yarn commands as your workflow requires.
- Remove wait: If you prefer the script to exit after the commands, replace the
wait $NODE_PIDwithkill $NODE_PIDright after your commands.
Happy coding!