-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from chenzhitong/update-contract
Updated documentation for contract development
- Loading branch information
Showing
6 changed files
with
63 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ The following steps are applicable to multiple system platforms, such as Windows | |
|
||
1. Download and install [Visual Studio Code](https://code.visualstudio.com/Download) | ||
|
||
2. Download and install [.NET 6.0 SDK](https://dotnet.microsoft.com/download) | ||
2. Download and install [.NET 8.0 SDK](https://dotnet.microsoft.com/download) | ||
|
||
3. Run the command line and enter the following command to check if you have installed SDK successfully. | ||
|
||
|
@@ -20,79 +20,56 @@ The following steps are applicable to multiple system platforms, such as Windows | |
|
||
## Installing contract template | ||
|
||
[Neo3.SmartContract.Templates](https://www.nuget.org/packages/Neo3.SmartContract.Templates/) contains the latest contract compiler and a hello contract template. The latest version is recommended: | ||
[Neo.SmartContract.Template](https://www.nuget.org/packages/Neo.SmartContract.Template) is a project template used when developing Neo smart contracts. After installing the template, you can create a Neo smart contract project using either the Terminal or Visual Studio. | ||
|
||
```powershell | ||
dotnet new -i Neo3.SmartContract.Templates | ||
``` | ||
|
||
## Creating a contract project | ||
|
||
1. Create a folder named `Nep17` as the contract project。 | ||
|
||
2. In the command line go to the `Nep17` path and then enter the command to generate code files based on the template. | ||
|
||
```powershell | ||
dotnet new neo3-contract | ||
``` | ||
|
||
You can find the files named by the folder name under `Nep17` directory: Nep17.cs and Nep17.csproj. | ||
|
||
If you want to specify the file name, add the option -n, for example, `dotnet new neo3-contract -n tokenA`. | ||
|
||
## Editing NEP17 code | ||
|
||
Since many developers are concerned about how to publish their own contract assets on the Neo block chain, now let's proceed with the NEP17 contract development on private chain. | ||
|
||
1. Download all the .cs files from [NEP17 Template](https://github.com/neo-project/examples/tree/master/csharp/NEP17) and place them under the `Nep17` directory. | ||
|
||
2. Remove the original Nep17.cs generated by the HelloContract template. | ||
|
||
3. Run VS Code and install the C# extension as prompted. | ||
### Install the template | ||
|
||
![](assets/extension.png) | ||
``` | ||
dotnet new install Neo.SmartContract.Template | ||
``` | ||
|
||
4. Open the `Nep17` folder to edit the Nep17 template。 | ||
### List all dotnet templates | ||
|
||
In comparison with Neo Legacy, the Neo N3 NEP17 sample has the following changes: | ||
``` | ||
dotnet new list | ||
``` | ||
|
||
- Added the customized attributes above the smart contract class | ||
These default templates are available after installing [Neo.SmartContract.Template](https://www.nuget.org/packages/Neo.SmartContract.Template): | ||
|
||
``` | ||
[DisplayName("Token Name")] | ||
[ManifestExtra("Author", "Neo")] | ||
[ManifestExtra("Email", "[email protected]")] | ||
[ManifestExtra("Description", "This is a NEP17 example")] | ||
[SupportedStandards("NEP-17")] | ||
[ContractPermission("*", "onNEP17Payment")] | ||
public class NEP17 : SmartContract | ||
…… | ||
``` | ||
- neocontractowner - Standard contract template with the Owner, including the GetOwner and SetOwner methods. | ||
|
||
- Removed the Name method | ||
- neocontractoracle - A contract template using OracleRequest. | ||
|
||
- Added _deploy method, which will be executed immediately after the contract is deployed | ||
- neocontractnep17 - NEP-17 contract template, including the Mint and Burn methods. | ||
|
||
- Added the Update and Destroy methods | ||
:::note | ||
|
||
- All the Crowdsale methods are in the NEP17.Crowdsale.cs file. Developers can choose to use this file if need be. | ||
The `neocontract` template previously used has been renamed to `neocontractowner`. | ||
|
||
- Called the onNEP17Payment method of the recipient in the Transfer method | ||
::: | ||
|
||
- Implemented onNEP17Payment to automatically execute the smart contract when NEP17 assets are received. | ||
### Create a project using templates with Terminal | ||
|
||
- Major changes occurred in smart contract framework. For details refer to [Smart Contract API](../reference/scapi/interop.md) | ||
``` | ||
dotnet new neocontractnep17 | ||
``` | ||
|
||
For more information refer to [NEP-17](../develop/write/nep17.md) . | ||
The project name defaults to the name of the current directory. You can also specify the project name with `-n, --name <name>`, e.g. `dotnet new neocontractnep17 -n MyFirstContract`. | ||
|
||
## Compiling contract file | ||
|
||
Run the following command to build your contract: | ||
In the Terminal interface, go to the project path and run the following command to build your contract: | ||
|
||
```powershell | ||
``` | ||
dotnet build | ||
``` | ||
|
||
or | ||
|
||
``` | ||
nccs | ||
``` | ||
|
||
Related contract files are outputted under `bin\sc` path in the contract project directory. | ||
|
||
## See also | ||
|