Page 59 - MSDN Magazine, November 2019
P. 59

• Inspect the Contents of emulated storage
• Inspect the Value of local parameters and variables
In order to deploy the smart contract, you need a PrivateNet instance of the blockchain. NEO Express is a developer-focused private network that’s built on the MainNet code base and pro- vides full symmetry with the MainNet. We’ll use NEO Express to
illustrate the steps involved in deployment.
By default, NEO Express creates a single-node blockchain.
Create a new NEO Express instance with the create command. You’ll see something like the output in Figure 5.
By default, NEO Express creates a single-node blockchain, but you can create a four- or seven-node blockchain with the --count option. Once you’ve created the NEO Express blockchain instance, you can run it. Because this is a single-node blockchain, you don’t need to specify which node of the blockchain to run. You can control the block generation period via the --seconds-per-block option (-s for short) of the run command.
Because this terminal window is running the blockchain, open another terminal window in the same directory so you can interact with the running PrivateNet. In the new terminal window, you’ll
Figure 4 Building the Smart Contract
create a standard wallet and transfer the “genesis” NEO tokens to that wallet, as you’ll need GAS to be able to deploy and invoke the contract, as shown in Figure 6.
You can see how much GAS is available with the show gas com- mand. In order to access the GAS, you need to execute another transfer, this time from and to the testWallet account. The avail- able GAS can be claimed with the claim gas command and you can see the result with the show account command.
With a running NEO Express blockchain and a standard wallet account with plenty of GAS, you can deploy the smart contract to the blockchain. You start by importing the contract into NEO Express. NEO Express needs to know if the contract uses storage, dynamic invoke or if the contract is payable in order to deploy the contract. For NEO 3, this information will be in the smart contract manifest file.
Figure 6 Deploying the Smart Contract on the PrivateNet
$ neo-express wallet create testWallet ...
$ neo-express transfer neo 100000000 genesis testWallet ...
$ neo-express show account testWallet {
... "balances": [
{ "asset":
"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", "value": "100000000"
} ]
}
$ neo-express show gas testWallet {
"unavailable": 1112,
"available": 0 }
$ neo-express transfer neo 100000000 testWallet testWallet ...
$ neo-express show gas testWallet {
"unavailable": 96,
"available": 1408 }
$ neo-express claim gas testWallet ...
$ neo-express show account testWallet {
... "balances": [
{ "asset":
"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", "value": "100000000"
}, {
"asset": "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
"value": "1408" }
] }
$ neo-express contract import bin/Debug/netstandard2.0/publish/ Does this contract use storage? [y/N] y
Does this contract use dynamic invoke? [y/N] n
Is this contract payable? [y/N] n
$ neo-express contract deploy HelloWorld testWallet ...
$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 294.77 ms for /home/jdevados/Source/HelloWorld/ HelloWorld.csproj.
HelloWorld -> /home/jdevados/Source/HelloWorld/bin/Debug/netstandard2.0/ HelloWorld.dll
HelloWorld -> /home/jdevados/Source/HelloWorld/bin/Debug/netstandard2.0/publish/ Neo.Compiler.MSIL console app v2.4.1.1
Find entrypoint:System.Void HelloWorld::Main()
convert succ
gen debug succ
gen md succ
gen abi succ write:HelloWorld.avm write:HelloWorld.debug.json write:HelloWorld.abi.json SUCC
Figure 5 Creating and Running the PrivateNet
$ neo-express create
Created 1 node privatenet at /home/jdevados/Source/HelloWorld/default.neo-express.json
Note: The private keys for the accounts in this file are are *not* encrypted. Do not use these accounts on MainNet or in any other system where
security is a concern.
$ neo-express run --seconds-per-block 1
09:49:37.99 ConsensusService Info OnStart
09:49:38.08 ConsensusService Info initialize: height=1 view=0 index=0 role=Primary 09:49:38.15 ConsensusService Info timeout: height=1 view=0
09:49:38.15 ConsensusService Info send prepare request: height=1 view=0 09:49:38.23 ConsensusService Info send commit
09:49:38.32 ConsensusService Info relay block: height=1 hash=0x096aaa25191b8601856a0a1744b7f19b06807fd9888e247366eec3d212a507b6 tx=1 09:49:41.32 ConsensusService Info persist block: height=1 hash=0x096aaa25191b8601856a0a1744b7f19b06807fd9888e247366eec3d212a507b6 tx=1 09:49:41.32 ConsensusService Info initialize: height=2 view=0 index=0 role=Primary 09:49:42.33 ConsensusService Info timeout: height=2 view=0
...
msdnmagazine.com
November 2019 47


































































































   57   58   59   60   61