In Neo N3 most of the functions are provided by contracts. ScriptHash is the unique identifier of the contract, and it is usually a necessary parameter for invoking contracts.
This document introduces the following SDK features:
The construction method of contract deployment transaction
Invoking methods in the contract under read-only mode
Nep17API class that encapsulates the methods for invoking NEP17 contracts
Contract deployment
ContractClient provides the method, CreateDeployContractTxAsync , to construct deployment transactions of the contract. The parameters are contract scripts, manifests, and account key pairs for payment of system and network fees, where contract scripts and manifests are available from the compilation. There must be sufficient GAS in the sender account.
Read the nef and manifest.json files of the contract:
Construct a contract deployment transaction:
After the transaction is constructed, you need to broadcast it on the blockchain:
After the transaction is added to the blockchain you can get the transaction execution status to check if the contract is deployed successfully:
Here is the complete code:
Contract invocation simulation
ContractClient provides the method TestInvokeAsync to simulate the contract invocation, which does not affect the data on the chain after execution. You can directly invoke the contract method that reads the data. For example, the following example invokes the name method in the NEO native contract.
Or you can use MakeScript to construct the script you want to execute and then invoke the method InvokeScriptAsync in RpcClient to get the execution result.
Contract invocation (on-chain transactions)
Generally invoking a deployed contract on the blockchain contains the following steps:
Construct the script to invoke
Take the transfer method of native contract Neo as an example:
Construct the transaction:
Broadcast the transaction on the blockchain:
Wait until the transaction is added to the blockchain and then get the transaction execution status to make sure the contract is invoked successfully: