Deploying a Smart Contract with Parameters
1 - Introduction
This tutorial is designed to cover how to deploy and invoke a smart contract on the NEO blockchain using the desktop GUI. The tutorial is generic and is appropriate for all contract types including NEP5 tokens. This tutorial assumes that the contract has already been compiled into a .avm file. If it has not, please reference the other tutorials first. A compiled version of the contract and the source used in this tutorial are provided.
2 - Useful Resources
The following resources are used in this tutorial and can be helful references when developing a smart contract:
3 - SC Code
This document will be using the example code provided in the Woolong example to walk through the tutorial. For fun, this contract will generate 1 Woolong for every invoke event.
The example has been deployed on the testnet and can be accessed at the following script hash:
4 - Deploying a Smart Contract with Parameters
- To deploy the smart contract (.avm) on the blockchain, click on the Advanced menu option on the NEO desktop wallet and select Deploy Contract. FOr development contracts, we recommend using the NEO development GUI.
- Populate all of the fields in the Information section of the window that appears. All fields must be populated to deploy the contract.
- Load the .avm file using the Load buttton. The code field will be populated with the script hash. Copy the contents of the Code field for use in a later step.
Populate the Metadata fields referencing the Parameter documentation.
The Woolong example token is defined as:
public static object Main(string method, params object args)
So we use:
- Parameter List: 0710
- Return Type: 05
If the contract requires storage (uses the Read/Write API), check the Need Storage box. The NEP5 standard uses storage to maintain accounts so make sure this is checked when deploying a NEP5 token.
Click the Deploy button.
5 - Watching the Smart Contract
- On the main NEO wallet window, right click on the address area and select (Create Contract Add > Custom)
- Select the Account that you want to associate the Contract with from the Related Account dropdown
- In the Parameter List field, populate the Parameter List values used in Step 4 of the Deploy Smart Contract w/ Parameters sections.
- Populate the Script field with the value provided in Step 3 of Deploy Smart Contract w/ Parameters.
- Click Confirm to load the contract into the wallet window.
6 - Invoking the Smart Contract
To invoke a smart contract on the NEO blockchain, you will need the smart contract script hash.
- To acquire the contract hash, right click on the contract account populated in the address window as a result of the Watching the Smart Contract window.
- Select View Contract to open a window containing information about the smart contract. Copy the value in the Script Hash field.
- Click on the Advanced menu option and select Invoke Contract.
- Populate the Script Hash field with the value copied in Step 2. As an example, you can invoke the Woolong using the script hash in Section 3
- The Smart Contract information should automatically populate in the remaining Invoke Function fields.
- To populate the input parameters, click on the ... button next the the Parameters field to open the parameter population menu.
Select the parameters on the left field and populate the variable values in the lower right field.
For example, invoking the following:
6e616d65when calling the Woolong, will return 'Woolong'.
csharp if (method == "name") return name;
73796d626f6cwill return 'WNG'.
csharp if (method == "symbol") return symbol;
62616c616e63654f66, 5fe459481de7b82f0636542ffe5445072f9357a1261515d6d3173c07c762743bwill return the current balance of Woolong that lllwvlvwll holds on the testnet.
csharp if (method == "balanceOf") return Storage.Get(Storage.CurrentContext, (byte) args);
Click OK to close the parameter input window.
- Click the Invoke button to invoke the smart contract.
Note: The current standard desktop GUI does not support viewing returns. Using the developer GUI is recommended when executing the events.