@@ -10,21 +10,26 @@ import {
10
10
} from "react-icons/fa" ;
11
11
import CodeBlock from "./CodeBlock" ;
12
12
13
- const solidityCode = `/// @notice Purchase an access key for the STAC collection
14
- function purchaseAccess() external payable returns (string memory) {
15
- require(msg.value == keyPrice, "Incorrect amount sent");
16
- require(bytes(accessKeys[ msg.sender]).length == 0,
17
- "You already have access ");
13
+ const solidityCode = `/// @notice Purchase an access code for the STAC collection
14
+ /// @return accessCode The generated access code
15
+ function purchaseAccessCode() external payable returns (string memory) {
16
+ require(msg.value == accessPrice, "Incorrect payment amount");
17
+ require(!hasPurchased[msg.sender], "Access already purchased ");
18
18
19
- // Generate a unique access key
20
- string memory accessKey = generateAccessKey(msg.sender);
21
- accessKeys[msg.sender] = accessKey;
22
- validKeys[accessKey] = true;
19
+ // Generate a unique access code
20
+ string memory accessCode = _generateAccessCode(msg.sender);
23
21
24
- // Emit event to notify external services
25
- emit KeyPurchased(msg.sender, accessKey);
22
+ // Hash and store the access code
23
+ accessRecords[msg.sender] = AccessData({
24
+ hashedCode: keccak256(abi.encodePacked(accessCode)),
25
+ expiryTime: block.timestamp + defaultValidityPeriod
26
+ });
27
+ hasPurchased[msg.sender] = true;
26
28
27
- return accessKey;
29
+ // Emit event to notify external systems
30
+ emit AccessCodeGenerated(msg.sender, accessRecords[msg.sender].expiryTime);
31
+
32
+ return accessCode;
28
33
}` ;
29
34
30
35
const SmartContractsSection = ( { className } ) => {
@@ -172,44 +177,32 @@ const SmartContractsSection = ({ className }) => {
172
177
< h3 className = "flex items-center text-2xl font-bold mb-4 bg-gray-100 text-black px-3 py-1 rounded-md border-1 border-gray-400 hover:bg-gray-300 transition-colors duration-300 shadow" >
173
178
Smart Contracts in stacchain
174
179
</ h3 >
180
+ < CodeBlock code = { solidityCode } />
181
+ < br />
175
182
< p className = "text-md leading-relaxed mb-4" >
176
183
This Solidity code demonstrates how users can securely purchase
177
- access keys for a STAC collection using blockchain technology.
178
- It ensures secure payments, generates unique keys, and prevents
179
- duplicate purchases.
184
+ access codes for a STAC collection using blockchain technology.
185
+ It ensures secure payments, generates unique user-specific
186
+ codes, and prevents duplicate purchases by tying each code to
187
+ the user’s wallet address.
180
188
</ p >
181
189
< p className = "text-md leading-relaxed mb-4" >
182
- Additionally, it emits an event (`KeyPurchased`) to notify
183
- external systems about the purchase. This is essential for
184
- tracking access keys off-chain and integrating with external
185
- tools like databases or APIs.
190
+ The contract emits events such as{ " " }
191
+ < code > AccessCodeGenerated</ code > and{ " " }
192
+ < code > AccessCodeRevoked</ code > to notify external systems about
193
+ purchases and revocations. These events facilitate seamless
194
+ integration with APIs, databases, or other external tools to
195
+ track and validate access.
196
+ </ p >
197
+ < p className = "text-md leading-relaxed mb-4" >
198
+ It also supports time-limited validity for access codes,
199
+ balancing user convenience and security. The actual codes are
200
+ not stored on-chain; instead, only their cryptographic hashes
201
+ are stored for validation.
186
202
</ p >
187
- < CodeBlock code = { solidityCode } />
188
203
</ div >
189
204
</ div >
190
205
</ div >
191
-
192
- { /* Call to Action */ }
193
- { /* <div className="bg-white p-6 rounded-md shadow-md mt-10">
194
- <h3
195
- id="get-involved"
196
- className="flex items-center text-2xl font-bold mb-4 bg-gray-100 text-black px-3 py-1 rounded-md border-1 border-gray-400 hover:bg-gray-300 transition-colors duration-300 shadow"
197
- >
198
- <FaHandsHelping className="mr-2 text-green-400" />
199
- Get Involved
200
- </h3>
201
- <p className="text-lg leading-relaxed mb-4">
202
- We invite developers and blockchain enthusiasts to contribute to our
203
- platform. Your participation can help us enhance the functionality
204
- and security of our ecosystem.
205
- </p>
206
- <a
207
- href="https://github.com/stacchain"
208
- className="inline-block px-6 py-3 bg-green-500 text-white font-semibold rounded-md hover:bg-green-600 transition-colors duration-300"
209
- >
210
- Join Our Community
211
- </a>
212
- </div> */ }
213
206
</ div >
214
207
</ section >
215
208
) ;
0 commit comments