neoneo-go/examples
Anna Shaleva 39e096da64 examples: use base64 to encode HASHY token ID
Base58 does not preserve one-to-one byte correspondence with the
original data, so different combinations of the same number of bytes
might have different encoded string length. We use GAS transfer to mint
HASHY token, where the token hash is Base58Encode(Ripemd160(data + txHash)).

The problem is that `invokescript` RPC call is used to define transfer tx
sysfee, thus, txHash during testinvoke differs from the actual one, that's
why resulting token ID may have different length during testinvoke and
real invoke. As far as we use token ID as a key to store contract
values, the storage price may also differ. The result is failing
TestNEP11_OwnerOf_BalanceOf_Transfer test due to `gas limit exceeded`
error:

```
    logger.go:130: 2021-06-10T21:09:08.984+0300	WARN	contract invocation failed	{"tx": "45a0220b19725eaa0a4d01fa7a6cdaac8498592e8f3b43bdde27aae7d9ecf635", "block": 5, "error": "error encountered at instruction 36 (SYSCALL): error during call from native: error encountered at instruction 22 (SYSCALL): failed to invoke syscall 1736177434: gas limit exceeded"}
    executor_test.go:219:
        	Error Trace:	executor_test.go:219
        	            				nep11_test.go:132
        	            				nep11_test.go:235
        	Error:      	Not equal:
        	            	expected: 0x2
        	            	actual  : 0x4
        	Test:       	TestNEP11_OwnerOf_BalanceOf_Transfer
```

Fixed by using base64 instead of base58 (base64 preserves the resulting
encoded string length for the same input length).
2021-06-11 13:57:59 +03:00
..
engine compiler: check emitted event names 2020-11-26 13:49:58 +03:00
events compiler: save both VM and smartcontract types 2020-12-09 22:35:22 +03:00
iterator core: add flags to Storage.Find 2021-01-15 21:12:08 +03:00
nft-nd examples: use base64 to encode HASHY token ID 2021-06-11 13:57:59 +03:00
nft-nd-nns cli,compiler: allow to specify manifest permissions 2021-06-04 11:16:22 +03:00
oracle examples: add a perfect oracle example 2021-04-06 22:50:42 +03:00
runtime core: rename Neo.Crypto.CheckSig interop 2021-05-11 18:37:55 +03:00
storage core: add flags to Storage.Find 2021-01-15 21:12:08 +03:00
timer core: rename Neo.Crypto.CheckSig interop 2021-05-11 18:37:55 +03:00
token core: rename Neo.Crypto.CheckSig interop 2021-05-11 18:37:55 +03:00
token-sale core: rename Neo.Crypto.CheckSig interop 2021-05-11 18:37:55 +03:00
my_wallet.json wallet: rename isdefault to isDefault 2021-05-14 10:31:31 +03:00
README.md docs: add NNS to examples documentation 2021-05-17 22:24:58 +03:00

NEO-GO smart contract examples

examples directory contains smart contract examples written in Go. These examples are aimed to demonstrate the basic usage of Go programming language to write NEO smart contracts as far as to provide a brief introduction to the NEO-specific interop package application.

Examples structure

Each example represents a separate folder with the smart contract content inside. The content is presented by the smart contract code written in Go and the smart contract configuration file with .yml extension.

Some contracts have a contract owner, which is needed for witness checking and represented by the owner string constant inside the smart contract code. The owner account address is taken from the my_wallet.json. The wallet is located under the examples directory, has a single account inside with the my_account label which can be decrypted with the qwerty password. You can use my_wallet.json to deploy example contracts.

See the table below for the detailed examples description.

Example Description
engine This contract demonstrates how to use runtime interop package which implements an API for System.Runtime.* NEO system calls. Please, refer to the runtime package documentation for details.
events The contract shows how execution notifications with the different arguments types can be sent with the help of runtime.Notify function of the runtime interop package. Please, refer to the runtime.Notify function documentation for details.
iterator This example describes a way to work with NEO iterators. Please, refer to the iterator package documentation for details.
nft-nd NEP-11 non-divisible NFT. See NEP-11 token standard specification for details.
nft-nd-nns Neo Name Service contract which is NEP-11 non-divisible NFT. The contract implements methods for Neo domain name system managing such as domains registration/transferring, records addition and names resolving.
oracle Oracle demo contract exposing two methods that you can use to process URLs. It uses oracle native contract, see interop package documentation also.
runtime This contract demonstrates how to use special _initialize and _deploy methods. See the compiler documentation for methods details. It also shows the pattern for checking owner witness inside the contract with the help of runtime.CheckWitness interop function.
storage The contract implements API for basic operations with a contract storage. It shows hos to use storage interop package. See the storage package documentation.
timer The idea of the contract is to count tick method invocations and destroy itself after the third invocation. It shows how to use contract.Call interop function to call, update (migrate) and destroy the contract. Please, refer to the contract.Call function documentation
token This contract implements NEP17 token standard (like NEO and GAS tokens) with all required methods and operations. See the NEP17 token standard specification for details.
token-sale The contract represents a token with allowance. It means that the token owner should approve token withdrawing before the transfer. The contract demonstrates how interop packages can be combined to work together.

Compile

Please, refer to the neo-go smart contract compiler documentation to compile example smart contracts.

Deploy

You can set up neo-go private network to deploy the example contracts. Please, refer to the consensus documentation to start your own privnet with neo-go nodes.

To deploy smart contracts, refer to the Deploying section of the compiler documentation.

Where to start

Feel free to explore neo-go smart contract development workshop to get the basic concepts of how to develop, compile, debug and deploy NEO smart contracts written in go.