mirror of
https://github.com/averel10/crypto_clash.git
synced 2026-03-12 19:08:11 +01:00
feat: initialize crypto_clash_contract with TypeScript, Hardhat, and deployment script
- Added package.json with scripts for compiling, deploying, and testing the contract. - Created deploy.ts script for deploying the HelloWorld contract and saving the contract address to config.json. - Configured TypeScript with tsconfig.json for Node.js environment and ES module support.
This commit is contained in:
31
crypto_clash_contract/contracts/testcontract.sol
Normal file
31
crypto_clash_contract/contracts/testcontract.sol
Normal file
@@ -0,0 +1,31 @@
|
||||
// Specifies the version of Solidity, using semantic versioning.
|
||||
// Learn more: https://solidity.readthedocs.io/en/v0.5.10/layout-of-source-files.html#pragma
|
||||
pragma solidity >=0.7.3;
|
||||
|
||||
// Defines a contract named `HelloWorld`.
|
||||
// A contract is a collection of functions and data (its state). Once deployed, a contract resides at a specific address on the Ethereum blockchain. Learn more: https://solidity.readthedocs.io/en/v0.5.10/structure-of-a-contract.html
|
||||
contract HelloWorld {
|
||||
|
||||
//Emitted when update function is called
|
||||
//Smart contract events are a way for your contract to communicate that something happened on the blockchain to your app front-end, which can be 'listening' for certain events and take action when they happen.
|
||||
event UpdatedMessages(string oldStr, string newStr);
|
||||
|
||||
// Declares a state variable `message` of type `string`.
|
||||
// State variables are variables whose values are permanently stored in contract storage. The keyword `public` makes variables accessible from outside a contract and creates a function that other contracts or clients can call to access the value.
|
||||
string public message;
|
||||
|
||||
// Similar to many class-based object-oriented languages, a constructor is a special function that is only executed upon contract creation.
|
||||
// Constructors are used to initialize the contract's data. Learn more:https://solidity.readthedocs.io/en/v0.5.10/contracts.html#constructors
|
||||
constructor(string memory initMessage) {
|
||||
|
||||
// Accepts a string argument `initMessage` and sets the value into the contract's `message` storage variable).
|
||||
message = initMessage;
|
||||
}
|
||||
|
||||
// A public function that accepts a string argument and updates the `message` storage variable.
|
||||
function update(string memory newMessage) public {
|
||||
string memory oldMsg = message;
|
||||
message = newMessage;
|
||||
emit UpdatedMessages(oldMsg, newMessage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user