Hello World
Initialize a project
Before writing a contract, first create a helloworld
directory. Enter the directory, and then create a helloworld.scrypt
file.
Write a contract
/**
* contract HelloWorld
*/
contract HelloWorld {
Sha256 hash;
public function unlock(bytes message) {
require(sha256(message) == this.hash);
}
}
Run the contract
Open the Run and Debug view of VS Code and click the Create launch.json file button to create the following configuration:
{
"version": "0.2.0",
"configurations": [
{
"type": "scrypt",
"request": "launch",
"name": "sCrypt: Debug Hello World",
"program": "${file}",
"constructorArgs": ["Sha256(b'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9')"], //字符串"hello world" 的sha256
"pubFunc": "unlock",
"pubFuncArgs": ["b'68656c6c6f20776f726c64'"] //字符串"hello world" 的 hex
}
]
}
Open helloworld.scrypt
, press F5 to start the debugger. The Debug Console will output Execution successful.
Congratulations, you have completed the development and call of the HelloWorld
contract.