diff --git a/docs/n3/develop/assets/neo-devpack-dotnet-1.png b/docs/n3/develop/assets/neo-devpack-dotnet-1.png new file mode 100644 index 0000000..a4cbd6a Binary files /dev/null and b/docs/n3/develop/assets/neo-devpack-dotnet-1.png differ diff --git a/docs/n3/develop/assets/neo-devpack-dotnet-2.png b/docs/n3/develop/assets/neo-devpack-dotnet-2.png new file mode 100644 index 0000000..38a0f60 Binary files /dev/null and b/docs/n3/develop/assets/neo-devpack-dotnet-2.png differ diff --git a/docs/n3/develop/tool/sdk/transaction.md b/docs/n3/develop/tool/sdk/transaction.md index 4b55a68..24ad327 100644 --- a/docs/n3/develop/tool/sdk/transaction.md +++ b/docs/n3/develop/tool/sdk/transaction.md @@ -3,7 +3,7 @@ `RpcClient` encapsulates the transaction construction module, which allows you to construct transactions in Neo N3 with specific parameters and methods to personalize your functions. This document introduces the relevant methods. :::note - If you use SDK to construct a transaction that requires a signature, you need to ensure that the RpcClient obeject and the network it is connected to are configured the same way, or the transaction constructed by the SDK will not be validated in the blockchain. To do so, load Neo-CLI config.json when constructing the RpcClient object, for example: + If you use SDK to construct a transaction that requires a signature, you need to ensure that the RpcClient object and the network it is connected to are configured the same way, or the transaction constructed by the SDK will not be validated in the blockchain. To do so, load Neo-CLI config.json when constructing the RpcClient object, for example: ::: > > RpcClient client = new RpcClient(new Uri("http://localhost:20332"), null, null, ProtocolSettings.Load("config.json")) @@ -75,6 +75,7 @@ using Neo.SmartContract.Native; using Neo.VM; using Neo.Wallets; using System; +using Utility = Neo.Network.RPC.Utility; namespace ConsoleApp1 { @@ -88,8 +89,11 @@ namespace ConsoleApp1 private static async Task TestNep17Transfer() { + // get the protocol settings of the network + ProtocolSettings protocolSettings = ProtocolSettings.Load("/path/to/config.testnet.json"); + // choose a neo node with rpc opened - RpcClient client = new RpcClient("http://127.0.0.1:10332"); + RpcClient client = new RpcClient(new Uri("http://127.0.0.1:10332"), null, null, protocolSettings); // get the KeyPair of your account, which will pay the system and network fee KeyPair sendKey = Utility.GetKeyPair("L53tg72Az8QhYUAyyqTQ3LaXMXBE3S9mJGGZVKHBryZxya7prwhZ"); UInt160 sender = Contract.CreateSignatureContract(sendKey.PublicKey).ScriptHash; @@ -98,15 +102,15 @@ namespace ConsoleApp1 Signer[] cosigners = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; // get the scripthash of the account you want to transfer to - UInt160 receiver = Utility.GetScriptHash("NirHUAteaMr6CqWuAAMaEUScPcS3FDKebM"); + UInt160 receiver = Utility.GetScriptHash("NirHUAteaMr6CqWuAAMaEUScPcS3FDKebM", protocolSettings); // construct the script, in this example, we will transfer 1024 NEO to receiver UInt160 scriptHash = NativeContract.NEO.Hash; - byte[] script = scriptHash.MakeScript("transfer", sender, receiver, 1024); + byte[] script = scriptHash.MakeScript("transfer", sender, receiver, 1024, null); // initialize the TransactionManagerFactory with rpc client and magic // fill in the TransactionManager with the script and cosigners - TransactionManager txManager = await new TransactionManagerFactory(client, 5195086) + TransactionManager txManager = await new TransactionManagerFactory(client) .MakeTransactionAsync(script, cosigners).ConfigureAwait(false); // add signature and sign transaction with the added signature Transaction tx = await txManager.AddSignature(sendKey).SignAsync().ConfigureAwait(false); @@ -135,6 +139,7 @@ using Neo.SmartContract.Native; using Neo.VM; using Neo.Wallets; using System; +using Utility = Neo.Network.RPC.Utility; namespace ConsoleApp1 { @@ -148,17 +153,20 @@ namespace ConsoleApp1 private static async Task TestNep17Transfer() { + // get the protocol settings of the network + ProtocolSettings protocolSettings = ProtocolSettings.Load("/path/to/config.testnet.json"); + // choose a neo node with rpc opened - RpcClient client = new RpcClient("http://127.0.0.1:10332"); + RpcClient client = new RpcClient(new Uri("http://127.0.0.1:10332"), null, null, protocolSettings); // get the KeyPair of your account, which will pay the system and network fee KeyPair sendKey = Utility.GetKeyPair("L53tg72Az8QhYUAyyqTQ3LaXMXBE3S9mJGGZVKHBryZxya7prwhZ"); // get the scripthash of the account you want to transfer to - UInt160 receiver = Utility.GetScriptHash("NirHUAteaMr6CqWuAAMaEUScPcS3FDKebM"); + UInt160 receiver = Utility.GetScriptHash("NirHUAteaMr6CqWuAAMaEUScPcS3FDKebM", protocolSettings); // use WalletAPI to create and send the transfer transaction WalletAPI walletAPI = new WalletAPI(client); - Transaction tx = await walletAPI.TransferAsync(NativeContract.NEO.Hash, sendKey, receiver, 1024).ConfigureAwait(false); + Transaction tx = await walletAPI.TransferAsync(NativeContract.NEO.Hash, sendKey, receiver, 1024, null).ConfigureAwait(false); // print a message after the transaction is on chain WalletAPI neoAPI = new WalletAPI(client); @@ -175,6 +183,7 @@ The following example implements a function that transfers 10 GAS to a multi-sig ```cs using Neo; +using Neo.Cryptography.ECC; using Neo.Network.P2P.Payloads; using Neo.Network.RPC; using Neo.SmartContract; @@ -196,8 +205,11 @@ namespace ConsoleApp1 private static async Task TestToMultiTransfer() { + // get the protocol settings of the network + ProtocolSettings protocolSettings = ProtocolSettings.Load("/path/to/config.testnet.json"); + // choose a neo node with rpc opened - RpcClient client = new RpcClient("http://127.0.0.1:10332"); + RpcClient client = new RpcClient(new Uri("http://127.0.0.1:10332"), null, null, protocolSettings); // get the KeyPair of your account, which will pay the system and network fee KeyPair sendKey = Utility.GetKeyPair("L53tg72Az8QhYUAyyqTQ3LaXMXBE3S9mJGGZVKHBryZxya7prwhZ"); UInt160 sender = Contract.CreateSignatureContract(sendKey.PublicKey).ScriptHash; @@ -206,22 +218,28 @@ namespace ConsoleApp1 KeyPair key2 = Utility.GetKeyPair("L1bQBbZWnKbPkpHM3jXWD3E5NwK7nui2eWHYXVZPy3t8jSFF1Qj3"); KeyPair key3 = Utility.GetKeyPair("KwrJfYyc7KWfZG5h97SYfcCQyW4jRw1njmHo48kZhZmuQWeTtUHM"); + // add the KeyPairs to IReadOnlyCollection + IReadOnlyCollection keys = new List() + { + sendKey.PublicKey, key2.PublicKey, key3.PublicKey + }; + // create multi-signatures contract, this contract needs at least 2 of 3 KeyPairs to sign - Contract multiContract = Contract.CreateMultiSigContract(2, sendKey.PublicKey, key2.PublicKey, key3.PublicKey); + Contract multiContract = Contract.CreateMultiSigContract(2, keys); // get the scripthash of the multi-signature Contract UInt160 multiAccount = multiContract.Script.ToScriptHash(); // construct the script, in this example, we will transfer 1024 GAS to multi-sign account // in contract parameter, the amount type is BigInteger, so we need to muliply the contract factor UInt160 scriptHash = NativeContract.GAS.Hash; - byte[] script = scriptHash.MakeScript("transfer", sender, multiAccount, 1024 * NativeContract.GAS.Factor); + byte[] script = scriptHash.MakeScript("transfer", sender, multiAccount, 1024 * NativeContract.GAS.Factor, null); // add Signers, which is a collection of scripthashs that need to be signed Signer[] cosigners = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; // initialize the TransactionManager with rpc client and magic // fill the script and cosigners - TransactionManager txManager = await new TransactionManagerFactory(client, 5195086) + TransactionManager txManager = await new TransactionManagerFactory(client) .MakeTransactionAsync(script, cosigners).ConfigureAwait(false); // add signature and sign transaction with the added signature Transaction tx = await txManager.AddSignature(sendKey).SignAsync().ConfigureAwait(false); @@ -245,6 +263,7 @@ The following example implements a function that transfers 1024 GAS from a multi ```cs using Neo; +using Neo.Cryptography.ECC; using Neo.Network.P2P.Payloads; using Neo.Network.RPC; using Neo.SmartContract; @@ -266,16 +285,25 @@ namespace ConsoleApp1 private static async Task TestFromMultiTransfer() { + // get the protocol settings of the network + ProtocolSettings protocolSettings = ProtocolSettings.Load("/path/to/config.testnet.json"); + // choose a neo node with rpc opened - RpcClient client = new RpcClient("http://127.0.0.1:10332"); + RpcClient client = new RpcClient(new Uri("http://127.0.0.1:10332"), null, null, protocolSettings); // get the KeyPair of your account KeyPair receiverKey = Utility.GetKeyPair("L53tg72Az8QhYUAyyqTQ3LaXMXBE3S9mJGGZVKHBryZxya7prwhZ"); KeyPair key2 = Utility.GetKeyPair("L1bQBbZWnKbPkpHM3jXWD3E5NwK7nui2eWHYXVZPy3t8jSFF1Qj3"); KeyPair key3 = Utility.GetKeyPair("KwrJfYyc7KWfZG5h97SYfcCQyW4jRw1njmHo48kZhZmuQWeTtUHM"); + // add the KeyPairs to IReadOnlyCollection + IReadOnlyCollection keys = new List() + { + receiverKey.PublicKey, key2.PublicKey, key3.PublicKey + }; + // create multi-signature contract, this contract needs at least 2 of 3 KeyPairs to sign - Contract multiContract = Contract.CreateMultiSigContract(2, receiverKey.PublicKey, key2.PublicKey, key3.PublicKey); + Contract multiContract = Contract.CreateMultiSigContract(2, keys); // get the scripthash of the multi-signature Contract UInt160 multiAccount = multiContract.Script.ToScriptHash(); @@ -284,17 +312,17 @@ namespace ConsoleApp1 // construct the script, in this example, we will transfer 1024 GAS to multi-sign account // in contract parameter, the amount type is BigInteger, so we need to muliply the contract factor UInt160 scriptHash = NativeContract.GAS.Hash; - byte[] script = scriptHash.MakeScript("transfer", multiAccount, receiver, 1024 * NativeContract.GAS.Factor); + byte[] script = scriptHash.MakeScript("transfer", multiAccount, receiver, 1024 * NativeContract.GAS.Factor, null); // add Signers, which is a collection of scripthashs that need to be signed Signer[] cosigners = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = multiAccount } }; // initialize the TransactionManager with rpc client and magic // fill the script and cosigners - TransactionManager txManager = await new TransactionManagerFactory(client, 5195086) + TransactionManager txManager = await new TransactionManagerFactory(client) .MakeTransactionAsync(script, cosigners).ConfigureAwait(false); // add signature and sign transaction with the added signature - Transaction tx = await txManager.AddMultiSig(new KeyPair[]{receiverKey, key2}, 2, receiverKey.PublicKey, key2.PublicKey, key3.PublicKey) + Transaction tx = await txManager.AddMultiSig(new KeyPair[] { receiverKey, key2 }, 2, receiverKey.PublicKey, key2.PublicKey, key3.PublicKey) .SignAsync().ConfigureAwait(false); // broadcasts the transaction over the Neo network. diff --git a/docs/n3/develop/write/1_dotnet.md b/docs/n3/develop/write/1_dotnet.md new file mode 100644 index 0000000..612069a --- /dev/null +++ b/docs/n3/develop/write/1_dotnet.md @@ -0,0 +1,159 @@ +# Using Neo Devpack Dotnet + +Designed for developers, Neo Devpack Dotnet is a comprehensive toolkit for creating Neo contracts using .net. It offers convenient contract project templates and a compiler. + +When developing and deploying a contract, the typical process is the following: + +- Installing a project template +- Creating a project using templates +- Writing a contract +- Compiling the contract +- Deploying and testing it + +This document covers the usage of project templates and the compiler. For further details on writing and deploying your contract, refer to the subsequent sections. + +:::note + +- Ensure that you install project templates and compilers with matching or the most recent versions when setting them up. + +- If it's been a long while since you last updated your project templates and compiler, make sure to update both when using them again. + +::: + +## Neo.SmartContract.Template + +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. + +### Install the template + +``` +dotnet new install Neo.SmartContract.Template +``` + +### List all dotnet templates + +``` +dotnet new list +``` + +### Uninstall the template + +``` +dotnet new uninstall Neo.SmartContract.Template +``` + +### Update the template + +``` +dotnet new update Neo.SmartContract.Template +``` + +### Create a project using templates with Terminal + +``` +dotnet new neocontract +``` + +The project name defaults to the name of the current directory, you can also specify the project name with `-n, --name `, e.g. `dotnet new neocontract -n MyFirstContract`. + +### Create a project using templates with Visual Studio + +In the Visual Studio interface, create a new project, Neo.SmartContract.Template, as shown in the following screenshots: + +![](../assets/neo-devpack-dotnet-1.png) + +![](../assets/neo-devpack-dotnet-2.png) + + + +## Neo.Compiler.CSharp + +Neo.Compiler.CSharp (nccs) is the Neo smart contract compiler that compiles the C# language into NeoVM executable OpCodes. + +In the project file of the contract project template, you can find the following code, + + +```xml + + + + +``` + +which is designed to trigger a secondary compilation with `nccs` after a successful C# compilation. This secondary compilation compiles it to a `nef` file and outputs the `manifest.json` file. + +Among them, .nef stands for NEO Executable Format, which mainly contains the contracts's executable code. The specific structure can be found on [GitHub](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/NefFile.cs). + +manifest.json represents the manifest of a smart contract. When a smart contract is deployed, it must explicitly declare the features and permissions it will use. + +When running, it will be restricted by its declared list of features and permissions, and cannot exhibit any behavior outside the scope of the list. + +### Install the compiler + +``` +dotnet tool install --global Neo.Compiler.CSharp +``` + +### List all dotnet tools + +``` +dotnet tool list +``` + +### Uninstall the compiler + +``` +dotnet tool uninstall --global Neo.Compiler.CSharp +``` + +### Update the compiler + +``` +dotnet tool update --global Neo.Compiler.CSharp +``` + +### Compile the contract file with Terminal + +In the Terminal interface, go to the project path and run the following command to build your contract: + +``` +dotnet build +``` + +or + +``` +nccs +``` + +Related contract files are outputted under `bin\sc` path in the contract project directory. + +### Compile the contract file with Visual Studio + +In the Visual Studio interface, click Build -> Build Solution (Ctrl + Shift + B). + +## Versioning tips + +- After successfully creating the project, open it and check if the version of the NuGet package `Neo.SmartContract.Framework` matches the version of `Neo.Compiler.CSharp`. If the compiler is up-to-date but Neo.SmartContract.Framework is not, please manually update it to ensure the proper compilation of the project. + +- If you're working on an older contract project, make sure to compile it using the appropriate compiler version. + +- If you are updating a contract project that is quite old, ensure that you have upgraded both the NuGet package `Neo.SmartContract.Framework` and the compiler to the latest versions, and also make necessary modifications to the contract code. + +- For the most current way of writing contract code, see this document or [GitHub](https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples). Among other things, the example contracts in GitHub may contain code for the upcoming version (unreleased) of the template and compiler. + +## References + +[NuGet (Neo.SmartContract.Template)](https://www.nuget.org/packages/Neo.SmartContract.Template) + +[NuGet (Neo.Compiler.CSharp)](https://www.nuget.org/packages/Neo.Compiler.CSharp) + +[GitHub (Neo-Devpack-Dotnet)](https://github.com/neo-project/neo-devpack-dotnet) + +[GitHub (example contracts)](https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples) + +Contract template for community maintenance: + +- [Neo3.SmartContract.Templates](https://www.nuget.org/packages/Neo3.SmartContract.Templates) by: shuaishuimen + +- [NeoEvents.SmartContract.Templates](https://www.nuget.org/packages/NeoEvents.SmartContract.Templates) by: cschuchardt \ No newline at end of file diff --git a/docs/n3/fees.md b/docs/n3/fees.md index 50feee8..f18d9b3 100644 --- a/docs/n3/fees.md +++ b/docs/n3/fees.md @@ -29,18 +29,18 @@ System fees include: | Fee(GAS) | OpCode | | ---------- | ------------------------------------------------------------ | | 0.00032768 | CALLT | -| 0.00008192 | APPEND, REVERSEITEMS, SETITEM, VALUES | +| 0.00008192 | VALUES, APPEND, SETITEM, REVERSEITEMS, CONVERT | | 0.00004096 | PUSHDATA4 | -| 0.00002048 | CAT, CONVERT, LEFT, MEMCPY, RIGHT, SUBSTR | -| 0.00000512 | CALL, CALL_L, CALLA, NEWARRAY, NEWARRAY_T, NEWSTRUCT, PACK, PUSHDATA2, THROW, UNPACK | +| 0.00002048 | MEMCPY, CAT, SUBSTR, LEFT, RIGHT, MODPOW, PACKMAP, PACKSTRUCT, PACK, UNPACK | +| 0.00000512 | PUSHDATA2, CALL, CALL_L, CALLA, THROW, NEWARRAY, NEWARRAY_T, NEWSTRUCT | | 0.00000256 | NEWBUFFER | -| 0.00000064 | HASKEY, INITSLOT, PICKITEM | -| 0.00000032 | EQUAL, NOTEQUAL | -| 0.00000016 | CLEAR, CLEARITEMS, INITSSLOT, KEYS, NEWARRAY0, NEWSTRUCT0, POPITEM, REMOVE, REVERSEN, ROLL, XDROP | -| 0.00000008 | ADD, AND, BOOLAND, BOOLOR, DIV, GE, GT, LE, LT, MAX, MIN, MOD, MUL, NEWMAP, NUMEQUAL, NUMNOTEQUAL, OR, PUSHDATA1, SHL, SHR, SUB, WITHIN, XOR | -| 0.00000004 | ABS, DEC, ENDFINALLY, ENDTRY, ENDTRY_L, INC, INVERT, NEGATE, NOT, NZ, PUSHA, PUSHINT128, PUSHINT256, SIGN, SIZE, TRY, TRY_L | -| 0.00000002 | DEPTH, DROP, DUP, ISNULL, ISTYPE, JMP, JMP_L, JMPEQ, JMPEQ_L, JMPGE, JMPGE_L, JMPGT, JMPGT_L, JMPIF, JMPIF_L, JMPIFNOT, JMPIFNOT_L, JMPLE, JMPLE_L, JMPLT, JMPLT_L, JMPNE, JMPNE_L, LDARG, LDARG0, LDARG1, LDARG2, LDARG3, LDARG4, LDARG5, LDARG6, LDLOC, LDLOC0, LDLOC1, LDLOC2, LDLOC3, LDLOC4, LDLOC5, LDLOC6, LDSFLD, LDSFLD0, LDSFLD1, LDSFLD2, LDSFLD3, LDSFLD4, LDSFLD5, LDSFLD6, NIP, OVER, PICK, REVERSE3, REVERSE4, ROT, STARG, STARG0, STARG1, STARG2, STARG3, STARG4, STARG5, STARG6, STLOC, STLOC0, STLOC1, STLOC2, STLOC3, STLOC4, STLOC5, STLOC6, STSFLD, STSFLD0, STSFLD1, STSFLD2, STSFLD3, STSFLD4, STSFLD5, STSFLD6, SWAP, TUCK | -| 0.00000001 | ASSERT, NOP, PUSH0, PUSH1, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSHINT16, PUSHINT32, PUSHINT64, PUSHINT8, PUSHM1, PUSHNULL, PUSHT, PUSHF | +| 0.00000064 | INITSLOT, POW, SQRT, HASKEY, PICKITEM | +| 0.00000032 | EQUAL, NOTEQUAL, MODMUL | +| 0.00000016 | XDROP, CLEAR, ROLL, REVERSEN, INITSSLOT, NEWARRAY0, NEWSTRUCT0, KEYS, REMOVE, CLEARITEMS, POPITEM | +| 0.00000008 | PUSHDATA1, AND, OR, XOR, ADD, SUB, MUL, DIV, MOD, SHL, SHR, BOOLAND, BOOLOR, NUMEQUAL, NUMNOTEQUAL, LT, LE, GT, GE, MIN, MAX, WITHIN, NEWMAP | +| 0.00000004 | PUSHINT128, PUSHINT256, PUSHA, TRY, TRY_L, ENDTRY, ENDTRY_L, ENDFINALLY, INVERT, SIGN, ABS, NEGATE, INC, DEC, NOT, NZ, SIZE | +| 0.00000002 | JMP, JMP_L, JMPIF, JMPIF_L, JMPIFNOT, JMPIFNOT_L, JMPEQ, JMPEQ_L, JMPNE, JMPNE_L, JMPGT, JMPGT_L, JMPGE, JMPGE_L, JMPLT, JMPLT_L, JMPLE, JMPLE_L, DEPTH, DROP, NIP, DUP, OVER, PICK, TUCK, SWAP, ROT, REVERSE3, REVERSE4, LDSFLD0, LDSFLD1, LDSFLD2, LDSFLD3, LDSFLD4, LDSFLD5, LDSFLD6, LDSFLD, STSFLD0, STSFLD1, STSFLD2, STSFLD3, STSFLD4, STSFLD5, STSFLD6, STSFLD, LDLOC0, LDLOC1, LDLOC2, LDLOC3, LDLOC4, LDLOC5, LDLOC6, LDLOC, STLOC0, STLOC1, STLOC2, STLOC3, STLOC4, STLOC5, STLOC6, STLOC, LDARG0, LDARG1, LDARG2, LDARG3, LDARG4, LDARG5, LDARG6, LDARG, STARG0, STARG1, STARG2, STARG3, STARG4, STARG5, STARG6, STARG, ISNULL, ISTYPE | +| 0.00000001 | PUSHINT8, PUSHINT16, PUSHINT32, PUSHINT64, PUSHT, PUSHF, PUSHNULL, PUSHM1, PUSH0, PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, NOP, ASSERT | | 0 | ABORT, RET, SYSCALL | Reference: [ApplicationEngine.OpCodePrices.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.OpCodePrices.cs) diff --git a/docs/n3/reference/scapi/framework/native/ContractManagement.md b/docs/n3/reference/scapi/framework/native/ContractManagement.md index 10e706d..fe37576 100644 --- a/docs/n3/reference/scapi/framework/native/ContractManagement.md +++ b/docs/n3/reference/scapi/framework/native/ContractManagement.md @@ -20,11 +20,13 @@ public class ContractManagement ## Methods -| Name | Description | -| ------------------------------------------------------------ | -------------------------------------------------- | -| GetMinimumDeploymentFee() | Gets the minimum fee of contract deployment | -| [GetContract(UInt160 hash)](ContractManagement/GetContract.md) | Gets the contract based on the given contract hash | -| [Deploy(byte[] nefFile, string manifest)](ContractManagement/Deploy.md) | Deploys the contract | -| [Update(byte[] nefFile, string manifest)](ContractManagement/Update.md) | Updates the contract | -| [Destroy()](ContractManagement/Destroy.md) | Destroys the contract | +| Name | Description | +| ------------------------------------------------------------ | ---------------------------------------------------- | +| [GetMinimumDeploymentFee()](ContractManagement/GetMinimumDeploymentFee) | Gets the minimum fee of contract deployment | +| [GetContract(UInt160 hash)](ContractManagement/GetContract.md) | Gets the contract based on the given contract hash | +| [GetContractById(int id)](ContractManagement/GetContractById.md) | Maps the specified ID to the deployed contract | +| [GetContractHashes()](ContractManagement/GetContractHashes.md) | Gets the hashes of all non-native deployed contracts | +| [Deploy(byte[] nefFile, string manifest)](ContractManagement/Deploy.md) | Deploys the contract | +| [Update(byte[] nefFile, string manifest)](ContractManagement/Update.md) | Updates the contract | +| [Destroy()](ContractManagement/Destroy.md) | Destroys the contract | diff --git a/docs/n3/reference/scapi/framework/native/ContractManagement/GetContractById.md b/docs/n3/reference/scapi/framework/native/ContractManagement/GetContractById.md new file mode 100644 index 0000000..27d5d73 --- /dev/null +++ b/docs/n3/reference/scapi/framework/native/ContractManagement/GetContractById.md @@ -0,0 +1,78 @@ +# ContractManagement.GetContractById Method + +Maps the specified ID to the deployed contract. + +Namespace: [Neo.SmartContract.Framework.Native](../../native.md) + +Assembly: Neo.SmartContract.Framework + +## Syntax + +```c# +public ContractState GetContractById(int id); +``` + +Parameters: + +- id: Contract ID. Negative numbers represent native contracts, while positive numbers represent normal contracts (non-native deployed contracts). + +## Example + +Contract: + +```c# +public class Contract1 : SmartContract +{ + public static string MyMethod(int id) + { + var contract = ContractManagement.GetContractById(id); + return contract.Manifest.Name; + } +} +``` + +Invoke from neo-cli: + +``` +invoke 0x425d355a8a62eebf961884c91c6567d3ff1ab0dc myMethod [{"type":"Integer","value":"-1"}] +``` + +Invoke from RPC: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "invokefunction", + "params": [ + "0x425d355a8a62eebf961884c91c6567d3ff1ab0dc", + "myMethod", + [ + { + "type": "Integer", + "value": "-1" + } + ] + ] +} +``` + +Response body: + +```json +[ + { + "type":"ByteString", + "value":"Q29udHJhY3RNYW5hZ2VtZW50" + } +] +``` + +Response description: + +According to the contract code, the contract name associated with the requested ID is returned here. + +The string `Q29udHJhY3RNYW5hZ2VtZW50`, when decoded with base64, yields `ContractManagement`. + +[Back](../ContractManagement.md) + diff --git a/docs/n3/reference/scapi/framework/native/ContractManagement/GetContractHashes.md b/docs/n3/reference/scapi/framework/native/ContractManagement/GetContractHashes.md new file mode 100644 index 0000000..4229b03 --- /dev/null +++ b/docs/n3/reference/scapi/framework/native/ContractManagement/GetContractHashes.md @@ -0,0 +1,155 @@ +# ContractManagement.GetContractById Method + +Gets the hashes of all non-native deployed contracts. + +Namespace: [Neo.SmartContract.Framework.Native](../../native.md) + +Assembly: Neo.SmartContract.Framework + +## Syntax + +```c# +private IIterator GetContractHashes() +``` + +Return: + +Iterator with hashes of all deployed contracts. + +## Example + +Contract: + +```c# +public static Iterator<(int, UInt160)> MyMethod() +{ + return ContractManagement.GetContractHashes(); +} +``` + +Invoke from RPC: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "invokefunction", + "params": [ + "0xc04ff111aa88cc5239cf36360cb298a9a3eae586", + "myMethod", + [] + ] +} +``` + +Response body: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "script": "wh8MCG15TWV0aG9kDBSG5eqjqZiyDDY2zzlSzIiqEfFPwEFifVtS", + "state": "HALT", + "gasconsumed": "2950200", + "exception": null, + "notifications": [], + "stack": [ + { + "type": "InteropInterface", + "interface": "IIterator", + "id": "0cd0591b-cf5a-4517-a060-779269f3577d" + } + ], + "session": "4829327b-8c1d-439e-becc-1360453839f6" + } +} +``` + +Invoke again from RPC to get the specific value of the iterator. For more information, refer to the command [traverseiterator](../../../../rpc/latest-version/api/traverseiterator.md). + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "traverseiterator", + "params": [ + "4829327b-8c1d-439e-becc-1360453839f6", + "0cd0591b-cf5a-4517-a060-779269f3577d", + 10 + ] +} +``` + +Response body: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "result": [ + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAAAQ==" + }, + { + "type": "ByteString", + "value": "3LAa/9NnZRzJhBiWv+5iilo1XUI=" + } + ] + }, + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAAAg==" + }, + { + "type": "ByteString", + "value": "gwlF8xm/6snmJCfRzDiaIiu40pI=" + } + ] + }, + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAAAw==" + }, + { + "type": "ByteString", + "value": "oDlHkjZPmX2hcY9E7b0Wdwwoxa8=" + } + ] + }, + { + "type": "Struct", + "value": [ + { + "type": "ByteString", + "value": "AAAABA==" + }, + { + "type": "ByteString", + "value": "huXqo6mYsgw2Ns85UsyIqhHxT8A=" + } + ] + } + ] +} +``` + +Response description: + +Each element of the returned array is a contract message containing the contract ID and Hash. + +Base64 string `AAAABA==` to hexadecimal string is `00000004`. + +Base64 script hash `huXqo6mYsgw2Ns85UsyIqhHxT8A=` to script hash (little-endian) is `86e5eaa3a998b20c3636cf3952cc88aa11f14fc0`. + +[Back](../ContractManagement.md) \ No newline at end of file diff --git a/docs/n3/reference/scapi/framework/native/ContractManagement/GetMinimumDeploymentFee.md b/docs/n3/reference/scapi/framework/native/ContractManagement/GetMinimumDeploymentFee.md new file mode 100644 index 0000000..7e86369 --- /dev/null +++ b/docs/n3/reference/scapi/framework/native/ContractManagement/GetMinimumDeploymentFee.md @@ -0,0 +1,70 @@ +# ContractManagement.GetMinimumDeploymentFee Method + +Gets the minimum GAS fee required for deploying a contract. + +Namespace: [Neo.SmartContract.Framework.Native](../../native.md) + +Assembly: Neo.SmartContract.Framework + +## Syntax + +```c# +public static long GetMinimumDeploymentFee(); +``` + +Return: + +GAS costs (in satoshi). + +## Example + +Contract: + +```c# +public class Contract_1 : SmartContract +{ + public static long MyMethod() + { + return ContractManagement.GetMinimumDeploymentFee(); + } +} +``` + +Invoke from neo-cli: + +``` +invoke 0x8143678f5c7140219d4f430a3e650653ded5fed7 myMethod +``` + +Invoke from RPC: + +```json +{ + "jsonrpc": "2.0", + "id": 1, + "method": "invokefunction", + "params": [ + "0x8143678f5c7140219d4f430a3e650653ded5fed7", + "myMethod", + [] + ] +} +``` + +Response body: + +```json +[ + { + "type":"Integer", + "value":"1000000000" + } +] +``` + +Response description: + +According to the return value, the minimum GAS for deploying a contract is 10.00000000 GAS. + +[Back](../ContractManagement.md) + diff --git a/docs/n3/reference/scapi/interop.md b/docs/n3/reference/scapi/interop.md index d4e662d..177486d 100644 --- a/docs/n3/reference/scapi/interop.md +++ b/docs/n3/reference/scapi/interop.md @@ -10,12 +10,12 @@ The Interoperable service is the underlying API of the system. For more informat **Contract**: -| API | Description | -| ------------------------------------- | ------------------------------------------------------------ | -| System.Contract.Call | Use it to call another contract dynamically. | -| System.Contract.GetCallFlags | Gets the CallFlags for the current context | -| System.Contract.CreateStandardAccount | Calculates corresponding account scripthash for the given public key | -| System.Contract.CreateMultisigAccount | Creates the script hash of multi-signed account using public key. | +| API | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| [System.Contract.Call](framework/services/Contract/Call.md) | Use it to call another contract dynamically. | +| [System.Contract.GetCallFlags](framework/services/Contract/CallEx.md) | Gets the CallFlags for the current context | +| [System.Contract.CreateStandardAccount](framework/services/Contract/CreateStandardAccount.md) | Calculates corresponding account scripthash for the given public key | +| System.Contract.CreateMultisigAccount | Creates the script hash of multi-signed account using public key. | **Crypto**: @@ -26,40 +26,40 @@ The Interoperable service is the underlying API of the system. For more informat **Iterator**: -| API | Description | -| ---------------------- | ------------------------------------------------------------ | -| System.Iterator.Next | Advances the iterator to the next element of the collection | -| System.Iterator.Values | Gets the element in the collection at the current position of the iterator | +| API | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| [System.Iterator.Next](framework/services/Iterator/Next.md) | Advances the iterator to the next element of the collection | +| [System.Iterator.Values](framework/services/Iterator/Value.md) | Gets the element in the collection at the current position of the iterator | **Runtime**: -| API | Description | -| ------------------------------------- | ------------------------------------------------------------ | -| System.Runtime.Platform | Gets the name of the current platform | -| System.Runtime.GetTrigger | Gets the trigger of the execution | -| System.Runtime.GetTime | Gets the timestamp of the current block | -| System.Runtime.GetScriptContainer | Gets the current script container | -| System.Runtime.GetExecutingScriptHash | Gets the script hash of the current context | -| System.Runtime.GetCallingScriptHash | Gets the script hash of the calling contract | -| System.Runtime.GetEntryScriptHash | Gets the script hash of the entry context | -| System.Runtime.CheckWitness | Determines whether the specified account has witnessed the current transaction | -| System.Runtime.GetInvocationCounter | Gets the number of times the current contract has been called during the execution | -| System.Runtime.Log | Writes a log | -| System.Runtime.GetNotifications | Gets the notifications sent by the specified contract during the execution | -| System.Runtime.GasLeft | Gets the remaining GAS that can be spent in order to complete the execution | -| System.Runtime.BurnGas | Burning GAS to benefit the Neo ecosystem | -| System.Runtime.GetNetwork | Gets the current network number | -| System.Runtime.GetRandom | Gets random number | +| API | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| System.Runtime.Platform | Gets the name of the current platform | +| [System.Runtime.GetTrigger](framework/services/Runtime/Trigger.md) | Gets the trigger of the execution | +| [System.Runtime.GetTime](framework/services/Runtime/Time.md) | Gets the timestamp of the current block | +| System.Runtime.GetScriptContainer | Gets the current script container | +| System.Runtime.GetExecutingScriptHash | Gets the script hash of the current context | +| System.Runtime.GetCallingScriptHash | Gets the script hash of the calling contract | +| System.Runtime.GetEntryScriptHash | Gets the script hash of the entry context | +| [System.Runtime.CheckWitness](framework/services/Runtime/CheckWitness.md) | Determines whether the specified account has witnessed the current transaction | +| System.Runtime.GetInvocationCounter | Gets the number of times the current contract has been called during the execution | +| [System.Runtime.Log](framework/services/Runtime/Log.md) | Writes a log | +| [System.Runtime.GetNotifications](framework/services/Runtime/GetNotifications.md) | Gets the notifications sent by the specified contract during the execution | +| System.Runtime.GasLeft | Gets the remaining GAS that can be spent in order to complete the execution | +| System.Runtime.BurnGas | Burning GAS to benefit the Neo ecosystem | +| System.Runtime.GetNetwork | Gets the current network number | +| System.Runtime.GetRandom | Gets random number | **Storage**: -| API | Description | -| --------------------------------- | ------------------------------------------------------------ | -| System.Storage.GetContext | Gets the storage context for the current contract | -| System.Storage.GetReadOnlyContext | Gets the read-only storage context for the current contract | -| System.StorageContext.AsReadOnly | Converts the specified storage context to a new read-only storage context | -| System.Storage.Get | Gets the entry with the specified key from the storage | -| System.Storage.Find | Finds the entries from the storage | -| System.Storage.Put | Puts a new entry into the storage | -| System.Storage.Delete | Deletes an entry from the storage | +| API | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| [System.Storage.GetContext](framework/services/Storage/CurrentContext.md) | Gets the storage context for the current contract | +| System.Storage.GetReadOnlyContext | Gets the read-only storage context for the current contract | +| System.StorageContext.AsReadOnly | Converts the specified storage context to a new read-only storage context | +| [System.Storage.Get](framework/services/Storage/Get.md) | Gets the entry with the specified key from the storage | +| [System.Storage.Find](framework/services/Storage/Find.md) | Finds the entries from the storage | +| [System.Storage.Put](framework/services/Storage/Put.md) | Puts a new entry into the storage | +| [System.Storage.Delete](framework/services/Storage/Delete.md) | Deletes an entry from the storage | diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/n3/fees.md b/i18n/zh/docusaurus-plugin-content-docs/current/n3/fees.md index 5ef73bc..145aae2 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/n3/fees.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/n3/fees.md @@ -28,21 +28,21 @@ sidebar_label: '合约费用' | 执行费用(GAS) | 操作码(OpCode)指令名称 | | --------------- | ------------------------------------------------------------ | | 0.00032768 | CALLT | -| 0.00008192 | APPEND, REVERSEITEMS, SETITEM, VALUES | +| 0.00008192 | VALUES, APPEND, SETITEM, REVERSEITEMS, CONVERT | | 0.00004096 | PUSHDATA4 | -| 0.00002048 | CAT, CONVERT, LEFT, MEMCPY, RIGHT, SUBSTR | -| 0.00000512 | CALL, CALL_L, CALLA, NEWARRAY, NEWARRAY_T, NEWSTRUCT, PACK, PUSHDATA2, THROW, UNPACK | +| 0.00002048 | MEMCPY, CAT, SUBSTR, LEFT, RIGHT, MODPOW, PACKMAP, PACKSTRUCT, PACK, UNPACK | +| 0.00000512 | PUSHDATA2, CALL, CALL_L, CALLA, THROW, NEWARRAY, NEWARRAY_T, NEWSTRUCT | | 0.00000256 | NEWBUFFER | -| 0.00000064 | HASKEY, INITSLOT, PICKITEM | -| 0.00000032 | EQUAL, NOTEQUAL | -| 0.00000016 | CLEAR, CLEARITEMS, INITSSLOT, KEYS, NEWARRAY0, NEWSTRUCT0, POPITEM, REMOVE, REVERSEN, ROLL, XDROP | -| 0.00000008 | ADD, AND, BOOLAND, BOOLOR, DIV, GE, GT, LE, LT, MAX, MIN, MOD, MUL, NEWMAP, NUMEQUAL, NUMNOTEQUAL, OR, PUSHDATA1, SHL, SHR, SUB, WITHIN, XOR | -| 0.00000004 | ABS, DEC, ENDFINALLY, ENDTRY, ENDTRY_L, INC, INVERT, NEGATE, NOT, NZ, PUSHA, PUSHINT128, PUSHINT256, SIGN, SIZE, TRY, TRY_L | -| 0.00000002 | DEPTH, DROP, DUP, ISNULL, ISTYPE, JMP, JMP_L, JMPEQ, JMPEQ_L, JMPGE, JMPGE_L, JMPGT, JMPGT_L, JMPIF, JMPIF_L, JMPIFNOT, JMPIFNOT_L, JMPLE, JMPLE_L, JMPLT, JMPLT_L, JMPNE, JMPNE_L, LDARG, LDARG0, LDARG1, LDARG2, LDARG3, LDARG4, LDARG5, LDARG6, LDLOC, LDLOC0, LDLOC1, LDLOC2, LDLOC3, LDLOC4, LDLOC5, LDLOC6, LDSFLD, LDSFLD0, LDSFLD1, LDSFLD2, LDSFLD3, LDSFLD4, LDSFLD5, LDSFLD6, NIP, OVER, PICK, REVERSE3, REVERSE4, ROT, STARG, STARG0, STARG1, STARG2, STARG3, STARG4, STARG5, STARG6, STLOC, STLOC0, STLOC1, STLOC2, STLOC3, STLOC4, STLOC5, STLOC6, STSFLD, STSFLD0, STSFLD1, STSFLD2, STSFLD3, STSFLD4, STSFLD5, STSFLD6, SWAP, TUCK | -| 0.00000001 | ASSERT, NOP, PUSH0, PUSH1, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSHINT16, PUSHINT32, PUSHINT64, PUSHINT8, PUSHM1, PUSHNULL, PUSHT, PUSHF | -| 0 | ABORT,RET,SYSCALL | +| 0.00000064 | INITSLOT, POW, SQRT, HASKEY, PICKITEM | +| 0.00000032 | EQUAL, NOTEQUAL, MODMUL | +| 0.00000016 | XDROP, CLEAR, ROLL, REVERSEN, INITSSLOT, NEWARRAY0, NEWSTRUCT0, KEYS, REMOVE, CLEARITEMS, POPITEM | +| 0.00000008 | PUSHDATA1, AND, OR, XOR, ADD, SUB, MUL, DIV, MOD, SHL, SHR, BOOLAND, BOOLOR, NUMEQUAL, NUMNOTEQUAL, LT, LE, GT, GE, MIN, MAX, WITHIN, NEWMAP | +| 0.00000004 | PUSHINT128, PUSHINT256, PUSHA, TRY, TRY_L, ENDTRY, ENDTRY_L, ENDFINALLY, INVERT, SIGN, ABS, NEGATE, INC, DEC, NOT, NZ, SIZE | +| 0.00000002 | JMP, JMP_L, JMPIF, JMPIF_L, JMPIFNOT, JMPIFNOT_L, JMPEQ, JMPEQ_L, JMPNE, JMPNE_L, JMPGT, JMPGT_L, JMPGE, JMPGE_L, JMPLT, JMPLT_L, JMPLE, JMPLE_L, DEPTH, DROP, NIP, DUP, OVER, PICK, TUCK, SWAP, ROT, REVERSE3, REVERSE4, LDSFLD0, LDSFLD1, LDSFLD2, LDSFLD3, LDSFLD4, LDSFLD5, LDSFLD6, LDSFLD, STSFLD0, STSFLD1, STSFLD2, STSFLD3, STSFLD4, STSFLD5, STSFLD6, STSFLD, LDLOC0, LDLOC1, LDLOC2, LDLOC3, LDLOC4, LDLOC5, LDLOC6, LDLOC, STLOC0, STLOC1, STLOC2, STLOC3, STLOC4, STLOC5, STLOC6, STLOC, LDARG0, LDARG1, LDARG2, LDARG3, LDARG4, LDARG5, LDARG6, LDARG, STARG0, STARG1, STARG2, STARG3, STARG4, STARG5, STARG6, STARG, ISNULL, ISTYPE | +| 0.00000001 | PUSHINT8, PUSHINT16, PUSHINT32, PUSHINT64, PUSHT, PUSHF, PUSHNULL, PUSHM1, PUSH0, PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, NOP, ASSERT | +| 0 | ABORT, RET, SYSCALL | -参考:[ApplicationEngine.OpCodePrices.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.OpCodePrices.cs) +参考:[ApplicationEngine.OpCodePrices.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.OpCodePrices.cs) ### 系统调用费用 @@ -75,15 +75,15 @@ sidebar_label: '合约费用' 参考: -[ApplicationEngine.Contract.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Contract.cs) +[ApplicationEngine.Contract.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.Contract.cs) -[ApplicationEngine.Crypto.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Crypto.cs) +[ApplicationEngine.Crypto.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.Crypto.cs) -[ApplicationEngine.Contract.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Contract.cs) +[ApplicationEngine.Contract.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.Contract.cs) -[ApplicationEngine.Iterator.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Iterator.cs) +[ApplicationEngine.Iterator.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.Iterator.cs) -[ApplicationEngine.Runtime.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Runtime.cs) +[ApplicationEngine.Runtime.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.Runtime.cs) [ApplicationEngine.Storage.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Storage.cs) @@ -109,7 +109,7 @@ sidebar_label: '合约费用' 其他未列出的原生合约方法的手续费均为 0.00032768 GAS。 -参考:[neo/SmartContract/Native](https://github.com/neo-project/neo/tree/master/src/neo/SmartContract/Native) +参考: [neo/SmartContract/Native](https://github.com/neo-project/neo/tree/master/src/Neo/SmartContract/Native) ### 存储区费用 @@ -125,7 +125,7 @@ sidebar_label: '合约费用' | 非首次写入存储区,且新数据大小 > 旧数据大小 | 与上一条相同 | 修改 value 为`hello neo3.0 preview5`, 共 21 字节 | 0.005 + (21-12)×0.001 = **0.014** GAS | | 删除 value | 0 | 删除 value | **0** GAS | -参考:[ApplicationEngine.Storage.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ApplicationEngine.Storage.cs) +参考:[ApplicationEngine.Storage.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/ApplicationEngine.Storage.cs) ## 网络手续费 @@ -140,7 +140,7 @@ sidebar_label: '合约费用' 参考: -[PolicyContract.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/Native/PolicyContract.cs) +[PolicyContract.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/Native/PolicyContract.cs) [Transaction.cs#L302](https://github.com/neo-project/neo/blob/ee898bf41667cdbe3b836b3bd08c2d3199046c2e/src/neo/Network/P2P/Payloads/Transaction.cs#L302) @@ -162,6 +162,6 @@ sidebar_label: '合约费用' 参考: -[PolicyContract.cs](https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/Native/PolicyContract.cs) +[PolicyContract.cs](https://github.com/neo-project/neo/blob/master/src/Neo/SmartContract/Native/PolicyContract.cs) [Transaction.cs#L302](https://github.com/neo-project/neo/blob/ee898bf41667cdbe3b836b3bd08c2d3199046c2e/src/neo/Network/P2P/Payloads/Transaction.cs#L302) \ No newline at end of file diff --git a/tutorials/2023-10-17-neow3j-sdk-quickstart/index.md b/tutorials/2023-10-17-neow3j-sdk-quickstart/index.md index d240e2a..35acdf1 100644 --- a/tutorials/2023-10-17-neow3j-sdk-quickstart/index.md +++ b/tutorials/2023-10-17-neow3j-sdk-quickstart/index.md @@ -12,7 +12,7 @@ sidebar: true
neow3j -

neow3j v3.21.2

+

neow3j v3.22.1

## 1. Introduction diff --git a/tutorials/2023-10-17-neow3j-smart-contract-quickstart/index.md b/tutorials/2023-10-17-neow3j-smart-contract-quickstart/index.md index 4388f70..48bd2dc 100644 --- a/tutorials/2023-10-17-neow3j-smart-contract-quickstart/index.md +++ b/tutorials/2023-10-17-neow3j-smart-contract-quickstart/index.md @@ -12,7 +12,7 @@ sidebar: true
neow3j -

neow3j v3.21.2

+

neow3j v3.22.1

## 1. Introduction diff --git a/tutorials/2023-10-17-neow3j-nep17/assets/neow3j-padded.png b/tutorials/2024-02-27-neow3j-nep11/assets/neow3j-padded.png similarity index 100% rename from tutorials/2023-10-17-neow3j-nep17/assets/neow3j-padded.png rename to tutorials/2024-02-27-neow3j-nep11/assets/neow3j-padded.png diff --git a/tutorials/2023-10-28-neow3j-nep11/index.md b/tutorials/2024-02-27-neow3j-nep11/index.md similarity index 97% rename from tutorials/2023-10-28-neow3j-nep11/index.md rename to tutorials/2024-02-27-neow3j-nep11/index.md index 75cf301..739168d 100644 --- a/tutorials/2023-10-28-neow3j-nep11/index.md +++ b/tutorials/2024-02-27-neow3j-nep11/index.md @@ -6,13 +6,13 @@ author: AxLabs tags: ["NEP-11", "JAVA", "NEOW3J"] skill: beginner image: "./assets/neow3j-padded.png" -source: https://github.com/neow3j/neow3j-examples-java/blob/7000d804257f8d573ac8cc369aa2a3abb303a751/src/main/java/io/neow3j/examples/contractdevelopment/contracts/NonFungibleToken.java +source: "https://github.com/neow3j/neow3j-examples-java/blob/7d462fab0dc27f7472b0cacf4beba6c08a7682e8/src/main/java/io/neow3j/examples/contractdevelopment/contracts/NonFungibleToken.java" sidebar: true ---
neow3j -

neow3j v3.21.2

+

neow3j v3.22.1

Neow3j is a development toolkit that provides easy and reliable tools to build Neo dApps and Smart Contracts using the @@ -243,9 +243,6 @@ public class NonFungibleToken { // endregion optional NEP-11 methods // region events - @DisplayName("Mint") - private static Event3Args> onMint; - @DisplayName("Transfer") private static Event4Args onTransfer; @@ -290,7 +287,7 @@ public class NonFungibleToken { increaseBalanceByOne(ctx, to); incrementTotalSupplyByOne(ctx); - onMint.fire(to, tokenId, properties); + onTransfer.fire(null, to, 1, tokenId); } public static void burn(ByteString tokenId) throws Exception { @@ -666,13 +663,9 @@ public static Map properties(ByteString tokenId) throws Exceptio The NEP-11 standard requires an event `Transfer` that contains the values `from`, `to`, `amount`, and `tokenId`. For this, the class `Event4Args` can be used with the annotation `@DisplayName` to set the event's name that will be shown -in the manifest and notifications when it has been fired. The event `Mint` is an additional custom event that is fired -whenever a new NFT is minted. +in the manifest and notifications when it has been fired. ```java -@DisplayName("Mint") -private static Event3Args> onMint; - @DisplayName("Transfer") private static Event4Args onTransfer; ``` @@ -691,7 +684,7 @@ The method `contractOwner()` simply returns the script hash of the contract owne The method `mint()` can be invoked by the contract owner in order to mint new NFT tokens. It stores the tokenId in the `registryMap`, its properties in the `propertiesMap`, and its owner in the `ownerMap`. Further, it increases the owner's -balance, and the total supply by 1, before it fires the `Mint` event. +balance, and the total supply by 1, before it fires the `Transfer` event. The method `burn()` can be invoked by the owner of a token. It deletes all information about the token and updates the balance and total supply accordingly. If the intent of burning a token need not require the storage to be freed, the @@ -736,7 +729,7 @@ public static void mint(Hash160 to, ByteString tokenId, Map prop increaseBalanceByOne(ctx, to); incrementTotalSupplyByOne(ctx); - onMint.fire(to, tokenId, properties); + onTransfer.fire(null, to, 1, tokenId); } public static void burn(ByteString tokenId) throws Exception { diff --git a/tutorials/2023-10-28-neow3j-nep11/assets/neow3j-padded.png b/tutorials/2024-02-27-neow3j-nep17/assets/neow3j-padded.png similarity index 100% rename from tutorials/2023-10-28-neow3j-nep11/assets/neow3j-padded.png rename to tutorials/2024-02-27-neow3j-nep17/assets/neow3j-padded.png diff --git a/tutorials/2023-10-17-neow3j-nep17/index.md b/tutorials/2024-02-27-neow3j-nep17/index.md similarity index 94% rename from tutorials/2023-10-17-neow3j-nep17/index.md rename to tutorials/2024-02-27-neow3j-nep17/index.md index 041525f..fbd871d 100644 --- a/tutorials/2023-10-17-neow3j-nep17/index.md +++ b/tutorials/2024-02-27-neow3j-nep17/index.md @@ -6,13 +6,13 @@ author: AxLabs tags: ["NEP-17", "JAVA", "NEOW3J"] skill: beginner image: "./assets/neow3j-padded.png" -source: "https://github.com/neow3j/neow3j-examples-java/blob/7000d804257f8d573ac8cc369aa2a3abb303a751/src/main/java/io/neow3j/examples/contractdevelopment/contracts/FungibleToken.java" +source: "https://github.com/neow3j/neow3j-examples-java/blob/7d462fab0dc27f7472b0cacf4beba6c08a7682e8/src/main/java/io/neow3j/examples/contractdevelopment/contracts/FungibleToken.java" sidebar: true ---
neow3j -

neow3j v3.21.2

+

neow3j v3.22.1

Neow3j is a development toolkit that provides easy and reliable tools to build Neo dApps and Smart Contracts using the @@ -39,6 +39,7 @@ package io.neow3j.examples.contractdevelopment.contracts; import io.neow3j.devpack.ByteString; import io.neow3j.devpack.Contract; import io.neow3j.devpack.Hash160; +import io.neow3j.devpack.Helper; import io.neow3j.devpack.Runtime; import io.neow3j.devpack.Storage; import io.neow3j.devpack.StorageContext; @@ -75,13 +76,15 @@ public class FungibleToken { if (!update) { StorageContext ctx = Storage.getStorageContext(); // Set the contract owner. - Storage.put(ctx, contractOwnerKey, (Hash160) data); + Hash160 initialOwner = (Hash160) data; + if (!Hash160.isValid(initialOwner)) Helper.abort("Invalid deployment parameter"); + Storage.put(ctx, contractOwnerKey, initialOwner); // Initialize the supply. int initialSupply = 200_000_000; Storage.put(ctx, totalSupplyKey, initialSupply); // Allocate all tokens to the contract owner. - new StorageMap(ctx, assetMapPrefix) - .put(contractOwner(ctx).toByteArray(), initialSupply); + new StorageMap(ctx, assetMapPrefix).put(initialOwner, initialSupply); + onTransfer.fire(null, initialOwner, initialSupply); } } @@ -205,6 +208,7 @@ package io.neow3j.examples.contractdevelopment.contracts; import io.neow3j.devpack.ByteString; import io.neow3j.devpack.Contract; import io.neow3j.devpack.Hash160; +import io.neow3j.devpack.Helper; import io.neow3j.devpack.Runtime; import io.neow3j.devpack.Storage; import io.neow3j.devpack.StorageContext; @@ -295,17 +299,19 @@ the `initialSupply` is set to 200'000'000 and it is allocated to the smart contr ```java @OnDeployment -public static void deploy(Object data, boolean update) throws Exception { +public static void deploy(Object data, boolean update) { if (!update) { StorageContext ctx = Storage.getStorageContext(); // Set the contract owner. - Storage.put(ctx, contractOwnerKey, (Hash160) data); + Hash160 initialOwner = (Hash160) data; + if (!Hash160.isValid(initialOwner)) Helper.abort("Invalid deployment parameter"); + Storage.put(ctx, contractOwnerKey, initialOwner); // Initialize the supply. int initialSupply = 200_000_000; Storage.put(ctx, totalSupplyKey, initialSupply); // Allocate all tokens to the contract owner. - new StorageMap(ctx, assetMapPrefix) - .put(contractOwner(ctx).toByteArray(), initialSupply); + new StorageMap(ctx, assetMapPrefix).put(initialOwner, initialSupply); + onTransfer.fire(null, initialOwner, initialSupply); } } ```