neo-devpack-solidity 0.22.0

Production-focused Solidity-to-NeoVM compilation system
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# Neo N3 Devpack for Solidity - Complete Guide

**A comprehensive development framework for building Neo N3 smart contracts in Solidity**

## ๐ŸŽฏ Overview

The Neo N3 Devpack provides Solidity-facing interfaces for Neo N3 features supported by the
`neo-devpack-solidity` compiler (syscalls, native contract calls, and NEP standard examples).

> Important: `neo-devpack-solidity` treats `Runtime`, `Storage`, `Syscalls`, `Neo`, `NativeCalls` and `abi`
> as **compiler intrinsics** (built-in libraries). Calls to supported members are lowered directly
> to Neo N3 syscalls / native contract calls. The Solidity bodies of these libraries are not
> compiled, and unsupported members will fail compilation with an error that lists the supported
> intrinsics.

## ๐Ÿš€ Quick Start

### Installation

```bash
# Install via npm
npm install --save-dev @neo-devpack-solidity/contracts hardhat@^2.28.6 @neo-devpack-solidity/hardhat-solc-neo @neo-devpack-solidity/hardhat-neo-deployer

# Or clone and build
git clone https://github.com/r3e-network/neo-devpack-solidity.git
cd neo-devpack-solidity/devpack
npm install
```

The current Hardhat plugins target Hardhat 2.28.x. Hardhat 3 uses a different plugin/runtime model
and needs a dedicated migration before it can be supported.

### Basic Usage

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@neo-devpack-solidity/contracts/standards/NEP17.sol";

contract MyToken is NEP17 {
    constructor() NEP17("My Token", "MTK", 18, 1000000, 10000000) {
        // Your token is now ready with full Neo N3 integration!
    }
}
```

## ๐Ÿ—๏ธ Deploying Contracts With Constructor Arguments

Neo N3 deployment invokes `_deploy(data, update)`. `neo-devpack-solidity` injects `_deploy` automatically.

When your Solidity contract constructor has parameters, pass them through `_deploy.data` as an
array of arguments:

- Neo-Express / CLI tooling: pass a JSON array string (for example `[7]`).
- SDKs that support StackItems directly may pass an Array value.
- Contract-to-contract deploy flows may pass StdLib.serialize(...) bytes (for example `abi.encode(...)`).

The injected deploy prologue attempts to parse `data` via `StdLib.jsonDeserialize`, then falls back
to `StdLib.deserialize` (binary serialization), and finally uses `data` as-is when native calls
throw. The resulting Array is then fed into the constructor.

This means the generated manifest will include permission entries for `StdLib.jsonDeserialize` and
`StdLib.deserialize`.

## ๐Ÿ“š Core Components

### ๐Ÿ—๏ธ FrameworkBase.sol

Base framework providing Neo N3 integration with minimally-permissioned manifests.

```solidity
import "@neo-devpack-solidity/contracts/contracts/FrameworkBase.sol";

contract MyContract is FrameworkBase {
    event MyEvent(string data);

    function myFunction() public withWitness {
        // Function requires valid witness (signature)

        // Access Neo blockchain data
        (uint256 blockIndex, bytes32 hash, uint256 timestamp,) = getCurrentBlock();

        // Interact with native contracts
        uint256 gasBalance = getBalance();

        // Emit Neo-compatible events
        emit MyEvent("data");
    }
}
```

### โš ๏ธ Framework.sol (Dynamic Calls)

`Framework.sol` extends `FrameworkBase.sol` and exposes `callContract(...)`, which performs fully
dynamic contract calls (dynamic target + method). This requires full wildcard permissions in the
Neo N3 manifest (`{"contract":"*","methods":"*"}`) and should be used only when you explicitly
need that surface.

To enforce manifest strictness in CI/production builds, compile with:

- `--deny-wildcard-permissions` (reject `{"contract":"*","methods":"*"}`)
- `--deny-wildcard-contracts` (reject any `{"contract":"*", ...}`)
- `--deny-wildcard-methods` (reject any `{..., "methods":"*"}`)

If you must keep dynamic calls but still want a deployable non-wildcard manifest, provide an explicit
allowlist and replace wildcard entries:

- `--manifest-permissions permissions.json --manifest-permissions-mode replace-wildcards`

Example `permissions.json`:

```json
[
  {
    "contract": "0x0102030405060708090a0b0c0d0e0f1011121314",
    "methods": ["ping"]
  }
]
```

### ๐Ÿ”ง Syscalls.sol

Neo N3 syscall (and syscall-like) integration used by `neo-devpack-solidity`:

```solidity
import "@neo-devpack-solidity/contracts/contracts/Syscalls.sol";

contract MySyscallContract {
    using Syscalls for *;

    function useBlockchain() public view {
        // Runtime / blockchain information
        uint256 currentHeight = Syscalls.getCurrentIndex();
        uint256 timeMs = Syscalls.getTime();

        // Crypto and witness checks
        bytes32 hash = Syscalls.sha256("data");
        bool verified = Syscalls.checkWitness(msg.sender);

        currentHeight;
        timeMs;
        hash;
        verified;
    }
}
```

### ๐Ÿ›๏ธ NativeCalls.sol

Direct integration with Neo native contracts:

```solidity
import "@neo-devpack-solidity/contracts/contracts/NativeCalls.sol";

contract MyNativeContract {
    using NativeCalls for *;

    function useNativeContracts() public {
        // NEO token operations
        uint256 neoBalance = NativeCalls.neoBalanceOf(msg.sender);
        bool success = NativeCalls.neoTransfer(msg.sender, address(this), 1, "");

        // GAS token operations
        uint256 gasBalance = NativeCalls.gasBalanceOf(msg.sender);

        // Contract management
        address newContract = NativeCalls.deployContract(nefData, manifestData);

        // Policy queries
        uint256 storagePrice = NativeCalls.getStoragePrice();

        // Oracle requests
        NativeCalls.requestOracleData("https://api.example.com", "$.price", "callback", "", 10000000);
    }
}
```

## ๐Ÿ“‹ NEP Standards

### ๐Ÿช™ NEP-17 Fungible Tokens

```solidity
import "@neo-devpack-solidity/contracts/standards/NEP17.sol";

contract MyNEP17Token is NEP17 {
    constructor() NEP17("My Token", "MTK", 18, 1000000, 0) {
        // Token with 18 decimals, 1M initial supply, no max supply
    }

    event CustomMint(address indexed to, uint256 amount);

    function customMint(address to, uint256 amount) public onlyMinter {
        mint(to, amount);

        // Emit custom event
        emit CustomMint(to, amount);
    }
}
```

### ๐ŸŽจ NEP-11 Non-Fungible Tokens

```solidity
import "@neo-devpack-solidity/contracts/standards/NEP11.sol";

contract MyNEP11NFT is NEP11 {
    constructor() NEP11("My NFT", "MNFT", 0, "https://api.mynft.com/", 10000, false) {
        // Indivisible NFT with 10k max supply
    }

    function mintNFT(address to, bytes memory metadata) public onlyMinter returns (bytes32) {
        bytes32 tokenId = bytes32(_currentTokenId++);
        mint(to, tokenId, metadata);
        return tokenId;
    }
}
```

### ๐Ÿ’ธ NEP-24 Royalties (NFT)

```solidity
import "@neo-devpack-solidity/contracts/standards/NEP24.sol";

contract MyRoyaltyMixin is NEP24Royalty {
    constructor(address recipient, uint96 bps) {
        // Example: 500 = 5%
        _setDefaultRoyalty(recipient, bps);
    }
}
```

## ๐Ÿ› ๏ธ Advanced Libraries

### ๐ŸŒ Neo.sol - Blockchain Utilities

```solidity
import "@neo-devpack-solidity/contracts/libraries/Neo.sol";
import "@neo-devpack-solidity/contracts/libraries/Runtime.sol";

contract MyContract {
    using Neo for *;
    using Runtime for *;

    function advancedOperations() public {
        // Account management (native contracts)
        uint256 neoBalance = Neo.getNeoBalance(msg.sender);
        uint256 gasBalance = Neo.getGasBalance(msg.sender);

        // Governance helpers (committee/validators are derived from public keys)
        bool isCommittee = Neo.isCommittee(msg.sender);
        bytes[] memory committee = Neo.getCommittee(); // ECPoint public keys (33 bytes each)

        // Contract interaction
        bytes memory result = Neo.callContract(targetContract, "method", params);

        // Security (Neo witness check)
        bool verified = Runtime.checkWitness(msg.sender);
        uint256 random = Neo.getRandom();

        neoBalance;
        gasBalance;
        isCommittee;
        committee;
        result;
        verified;
        random;
    }
}
```

### ๐Ÿ’พ Storage.sol - Advanced Storage

```solidity
import "@neo-devpack-solidity/contracts/libraries/Storage.sol";
import "@neo-devpack-solidity/contracts/contracts/Syscalls.sol";

contract MyStorageContract {
    using Storage for *;

    function advancedStorage() public {
        // Basic operations (lowered to System.Storage.*)
        Storage.put("key", abi.encode(uint256(123)));
        uint256 value = abi.decode(Storage.get("key"), (uint256));
        Storage.remove("key");

        // Iteration (Storage.find returns an iterator over [key, value] pairs)
        Syscalls.Iterator memory it = Storage.find("prefix");
        while (it.next()) {
            bytes memory k = it.currentKey;
            bytes memory v = it.value();
            k;
            v;
        }

        value;
    }
}
```

### โšก Runtime.sol - Runtime Services

```solidity
import "@neo-devpack-solidity/contracts/libraries/Runtime.sol";

contract MyRuntimeContract {
    using Runtime for *;

    event MyEvent(string data);

    function runtimeOperations() public {
        // Event emission (recommended)
        emit MyEvent("data");
        // Advanced: Runtime.notify("MyEvent", abi.encode("data")) (requires matching event declaration)

        // Authorization (Neo witness check)
        bool ok = Runtime.checkWitness(msg.sender);

        // Gas / time
        uint256 gasRemaining = Runtime.gasLeft();
        uint256 timeMs = Runtime.getTime();

        ok;
        gasRemaining;
        timeMs;
    }
}
```

## ๐ŸŽจ Complete Examples

### ๐Ÿ’ฐ Advanced NEP-17 Token

See [`examples/CompleteNEP17Token.sol`](./examples/CompleteNEP17Token.sol) for:

- โœ… Full NEP-17 compliance
- โœ… Staking system with rewards
- โœ… Oracle price integration
- โœ… Governance system
- โœ… Multi-signature operations
- โœ… Emergency controls
- โœ… Gas optimization

### ๐Ÿ–ผ๏ธ Advanced NEP-11 NFT

See [`examples/CompleteNEP11NFT.sol`](./examples/CompleteNEP11NFT.sol) for:

- โœ… NEP-11 method/event surface (note: manifest types deviate from the
  canonical NEP-11 spec โ€” `bytes32` token IDs emit as `Hash256`, `tokensOf`
  returns an `Array` instead of an iterator, `properties` returns `ByteArray`
  instead of `Map`; see `standards/STANDARDS_MAPPING.md` โ†’ "Manifest Type
  Deviations")
- โœ… Royalty system
- โœ… Marketplace integration
- โœ… Oracle metadata updates
- โœ… Curation system
- โœ… Fractionalization
- โœ… Bundle creation

## ๐Ÿ”ง Integration Examples

### Basic Token Implementation

```solidity
pragma solidity ^0.8.19;

import "@neo-devpack-solidity/contracts/standards/NEP17.sol";

contract SimpleToken is NEP17 {
    constructor() NEP17("Simple Token", "SIMPLE", 8, 1000000, 0) {
        // 1M tokens with 8 decimals, no max supply
    }

    // Token is ready to use with all Neo N3 features!
}
```

### Basic NFT Implementation

```solidity
pragma solidity ^0.8.19;

import "@neo-devpack-solidity/contracts/standards/NEP11.sol";

contract SimpleNFT is NEP11 {
    constructor() NEP11("Simple NFT", "SNFT", 0, "https://api.simple.nft/", 1000, false) {
        // Collection with 1000 max supply, indivisible
    }

    function mintNFT(address to, string memory metadata) public onlyMinter returns (bytes32) {
        bytes32 tokenId = generateTokenId(msg.sender, block.timestamp);
        mint(to, tokenId, bytes(metadata));
        return tokenId;
    }
}
```

### Oracle Integration (Native Oracle)

```solidity
pragma solidity ^0.8.19;

import "@neo-devpack-solidity/contracts/contracts/OracleService.sol";

contract PriceConsumer is IOracleServiceReceiver {
    OracleService private _oracle;
    mapping(string => uint256) public prices;

    constructor(address oracleService) {
        _oracle = OracleService(oracleService);
    }

    function updatePrice(string calldata symbol) external returns (uint256 requestId) {
        string memory url = string(abi.encodePacked("https://example.com/prices/", symbol));
        requestId = _oracle.request(url, "", abi.encode(symbol), 20_000_000);
    }

    function onOracleResponse(
        uint256,
        uint256 code,
        bytes calldata result,
        bytes calldata userData
    ) external override {
        require(msg.sender == address(_oracle), "unauthorized oracle response");
        if (code == 0) {
            string memory symbol = abi.decode(userData, (string));
            uint256 price = abi.decode(result, (uint256));
            prices[symbol] = price;
        }
    }
}
```

## ๐Ÿ”’ Security Best Practices

### Witness Verification

```solidity
contract SecureContract is Framework {
    function secureFunction() public withWitness {
        // Function automatically verifies witness
        // Only callable with valid signature
    }

    function manualWitnessCheck() public {
        require(Runtime.checkWitness(msg.sender), "Invalid witness");
        // Manual witness verification
    }

    function multiSigOperation(uint256 m, bytes[] memory publicKeys) public {
        // Neo witness checks work with standard and multisig account script hashes.
        address multisig = Syscalls.createMultisigAccount(m, publicKeys);
        require(Runtime.checkWitness(multisig), "Insufficient signatures");
    }
}
```

### Gas Management

```solidity
contract GasOptimizedContract is Framework {
    function expensiveOperation() public withGasLimit(50000000) { // Require ~0.5 GAS
        // Gas-intensive operation
    }

    function conditionalOperation() public {
        // Guard expensive work with a gas check.
        if (Runtime.gasLeft() < 10000000) {
            return;
        }

        // Execute only if enough gas.
    }
}
```

### Storage Security

```solidity
contract SecureStorageContract is Framework {
    using Storage for *;

    function secureStorage() public {
        // Secure storage with checksum (implement in-contract using Storage.put/get + keccak256).
        bytes memory value = abi.encode(secretValue);
        bytes32 checksum = keccak256(value);
        Storage.put("sensitive_data", abi.encode(value, checksum));

        bytes memory encoded = Storage.get("sensitive_data");
        if (encoded.length > 0) {
            (bytes memory inner, bytes32 storedChecksum) =
                abi.decode(encoded, (bytes, bytes32));
            require(keccak256(inner) == storedChecksum, "corrupt");
        }

        // Access-controlled storage
        require(Runtime.checkWitness(owner()), "unauthorized");
        Storage.put("admin_data", abi.encode(adminValue));

        // Expiring storage (example: expires after N blocks)
        Storage.put("temp_data", abi.encode(tempValue, block.number + 1000));
    }
}
```

## ๐Ÿ“Š Performance Optimization

### Batch Operations

```solidity
contract OptimizedContract is NEP17 {
    function batchTransfers() public {
        // Use built-in batch transfer
        address[] memory recipients = [addr1, addr2, addr3];
        uint256[] memory amounts = [100, 200, 300];
        batchTransfer(recipients, amounts, new bytes[](3));
    }

    function batchStorage() public {
        // Batch storage operations (simple loop)
        bytes[] memory keys = [key1, key2, key3];
        bytes[] memory values = [val1, val2, val3];
        for (uint256 i = 0; i < keys.length; i++) {
            Storage.put(keys[i], values[i]);
        }
    }
}
```

### Gas Optimization

```solidity
contract GasOptimized is Framework {
    function optimizedLoop() public {
        // Neo N3 exposes remaining gas via Runtime.GasLeft().
        // Use it to stop early if needed.
        for (uint256 i = 0; i < 1000; i++) {
            if (Runtime.gasLeft() < 5000) break;
            Storage.put(abi.encode("item", i), abi.encode(i * 2));
        }
    }
}
```

## ๐ŸŽฏ Deployment Guide

### Hardhat Configuration

Use Hardhat 2.28.x with the Neo plugins shown below. Hardhat 3 is intentionally outside the current
peer dependency range because its plugin API and network configuration model are incompatible with
these packages today.

```javascript
// hardhat.config.js
require("@neo-devpack-solidity/hardhat-solc-neo");
require("@neo-devpack-solidity/hardhat-neo-deployer");

module.exports = {
  solidity: {
    version: "0.8.19",
    settings: {
      optimizer: { enabled: true, runs: 200 },
      neo: {
        devpack: true,
        syscalls: "all",
        nativeContracts: "all",
        nepStandards: ["NEP-17", "NEP-11", "NEP-24", "NEP-22", "NEP-26", "NEP-27", "NEP-29", "NEP-30", "NEP-31"],
      },
    },
  },
  networks: {
    neo_testnet: {
      url: "http://seed1t5.neo.org:20332",
      accounts: ["your-private-key"],
    },
  },
};
```

### Deployment Workflow

Use the Neo-native Hardhat tasks exposed by `@neo-devpack-solidity/hardhat-solc-neo` and
`@neo-devpack-solidity/hardhat-neo-deployer`. They operate on Neo build artifacts and constructor arguments
encoded as a JSON array.

```bash
# Compile to Neo artifacts
npx hardhat neo-compile

# Deploy a compiled contract to Neo TestNet
npx hardhat neo-deploy \
  --network neo_testnet \
  --contract CompleteNEP17Token \
  --args '["My Token","MTK",18,1000000,10000000]'

# Verify on-chain NEF + manifest against the local build artifact
npx hardhat neo-verify \
  --network neo_testnet \
  --contract CompleteNEP17Token \
  --address <contract-address> \
  --constructor-args '["My Token","MTK",18,1000000,10000000]'
```

### Compilation

```bash
# Compile with Neo devpack
npx hardhat neo-compile

# Deploy to TestNet
npx hardhat neo-deploy --network neo_testnet --contract CompleteNEP17Token --args '["My Token","MTK",18,1000000,10000000]'

# Verify against deployed Neo bytecode + manifest
npx hardhat neo-verify --network neo_testnet --contract CompleteNEP17Token --address <contract-address> --constructor-args '["My Token","MTK",18,1000000,10000000]'
```

## ๐Ÿงช Testing

### Artifact-Level Integration Tests

```javascript
const { expect } = require("chai");
const fs = require("fs");
const path = require("path");
const hre = require("hardhat");

describe("Neo artifact generation", function () {
  it("writes Neo build-info and manifest outputs", async function () {
    await hre.run("neo-compile", { force: true, quiet: true });

    const buildInfoDir = path.join(__dirname, "..", "artifacts", "neo-build-info");
    const buildInfoFiles = fs.readdirSync(buildInfoDir).filter((file) => file.endsWith(".json"));

    expect(buildInfoFiles.length).to.be.greaterThan(0);

    const artifact = JSON.parse(
      fs.readFileSync(
        path.join(__dirname, "..", "artifacts", "contracts", "Framework.sol", "Framework.json"),
        "utf8"
      )
    );

    expect(artifact.contract.neo.manifest.name).to.equal("Framework");
    expect(artifact.contract.neo.manifest.abi.methods).to.not.be.empty;
  });
});
```

### Deployment Verification

After a successful `neo-deploy`, use `neo-verify` to compare the deployed contract's NEF script and
manifest with the local build artifact. This is the supported verification path for Neo deployments;
the generic EVM `hardhat verify` flow is not used here.

## ๐Ÿ“– API Reference

### Framework Methods

| Method              | Description              | Gas Cost  |
| ------------------- | ------------------------ | --------- |
| `getCurrentBlock()` | Get current block info   | Low       |
| `getBalance()`      | Get contract GAS balance | Low       |
| `transferGas()`     | Transfer GAS tokens      | Medium    |
| `callContract()`    | Call another contract    | High      |
| `deployContract()`  | Deploy new contract      | Very High |

### Storage Methods

| Method            | Description            | Gas Cost |
| ----------------- | ---------------------- | -------- |
| `put(key, value)` | Store value            | Medium   |
| `get(key)`        | Retrieve value         | Low      |
| `remove(key)`     | Delete value           | Low      |
| `find(prefix)`    | Find keys with prefix  | High     |

### Runtime Methods

| Method           | Description       | Gas Cost |
| ---------------- | ----------------- | -------- |
| `notify()`       | Emit event        | Low      |
| `checkWitness()` | Verify signature  | Medium   |
| `gasLeft()`      | Get remaining gas | Low      |
| `log()`          | Write to logs     | Low      |

## ๐Ÿšจ Error Handling

### Common Errors

```solidity
contract ErrorHandling is Framework {
    function handleErrors() public {
        try this.riskyOperation() {
            // Success
        } catch Error(string memory reason) {
            Runtime.log(string(abi.encodePacked("Error: ", reason)));
        } catch {
            Runtime.log("Unknown error occurred");
        }
    }

    function riskyOperation() external {
        require(Runtime.gasLeft() > 1000000, "Insufficient gas");
        require(Runtime.checkWitness(msg.sender), "Invalid witness");

        // Operation that might fail
    }
}
```

## ๐Ÿ“ˆ Best Practices

### 1. Always Use Witness Verification

```solidity
function secureFunction() public withWitness {
    // Secure by default
}
```

### 2. Optimize Gas Usage

```solidity
function batchOperation() public {
    // Prefer explicit batching + early exit when gas is low.
    for (uint256 i = 0; i < items.length; i++) {
        if (Runtime.gasLeft() < 5000) break;
        // ... process items[i]
    }
}
```

### 3. Use Typed Storage

```solidity
// Store typed values using abi.encode / abi.decode (NeoVM serialization),
// or prefer Solidity state variables/mappings when possible.
Storage.put("balance", abi.encode(amount));
```

### 4. Handle Oracle Responses

```solidity
function oracleCallback(string calldata url, bytes calldata userData, uint256 code, bytes calldata result) external {
    url; // optional: correlate callback source URL
    if (code == 0) {
        // Handle success
    } else {
        // Handle error
        Runtime.log("Oracle request failed");
    }
}
```

### 5. Implement Emergency Controls

```solidity
event EmergencyStop(address caller, uint256 timestamp);

function emergencyStop() public onlyOwner withWitness {
    // Emergency pause functionality
    _pause();
    emit EmergencyStop(msg.sender, block.timestamp);
}
```

## ๐ŸŽ“ Learning Resources

### Step-by-Step Tutorials

1. **[Basic Token]./examples/CompleteNEP17Token.sol** - Create your first NEP-17 token
2. **[NFT Collection]./examples/CompleteNEP11NFT.sol** - Build complete NFT marketplace
3. **[Oracle Integration]./contracts/OracleService.sol** - Use external data sources
4. **[DeFi Protocol]./examples/VaultPattern.sol** - Build advanced DeFi applications

### Code Examples

- **[Token Examples]./examples/** - Various token implementations
- **[NFT Examples]./examples/** - Different NFT use cases
- **[Oracle Examples]./examples/** - Oracle integration patterns
- **[DeFi Examples]./examples/** - DeFi protocol examples

## ๐Ÿ’ฌ Support

- **๐Ÿ“– Documentation**: Complete API reference and guides
- **๐Ÿ› Issues**: [GitHub Issues]https://github.com/r3e-network/neo-devpack-solidity/issues
- **๐Ÿ’ฌ Discord**: Community support and discussions
- **๐Ÿ“ง Email**: jimmy@r3e.network for technical support

## ๐Ÿค Contributing

1. Fork the repository
2. Create feature branch
3. Add tests for new features
4. Submit pull request
5. Follow our [contributing guidelines]../CONTRIBUTING.md

---

**Built with โค๏ธ by R3E Network**

_Bringing Ethereum's developer ecosystem to Neo blockchain with full N3 integration_