gitlab.com/aquachain/aquachain@v1.17.16-rc3.0.20221018032414-e3ddf1e1c055/Documentation/user-guide/Smart-Contracts.md (about) 1 # Smart Contracts 2 3 Something that sets Aquachain apart from other cryptocurrency is that we are able to write programs that exist on our blockchain. 4 5 AQUA uses the same stack based VM as Ethereum, and is compatible with all ETH smart contracts. 6 7 The use of tokens are discouraged. Think bigger. 8 There are some legitimate use-cases for the ERC20 standard, but for Aquachain, the ERC721 standard makes more sense to deploy. 9 10 Important: When deploying, use "Byzantium" EVM Target and Optimize code so it fits in the block. 11 12 Some opcodes do not exist here, such as CHAINID and CREATE2, and if your contract depends on these you must modify them. 13 14 15 ## Simple Example 16 17 18 Below is an example contract deployed on the aquachain at [0xF179C8ec4cE31d8B9f16fA12c88A6091fD06d62a](0xF179C8ec4cE31d8B9f16fA12c88A6091fD06d62a) 19 20 Copy paste this in your browser for [live demo](https://aquachain.github.io/explorer/#/contract/0xF179C8ec4cE31d8B9f16fA12c88A6091fD06d62a/double(int256)/100) (see Return Data: uint256): `https://aquachain.github.io/explorer/#/contract/0xF179C8ec4cE31d8B9f16fA12c88A6091fD06d62a/double(int256)/100` 21 22 23 It is a simple contract that demonstrates two things: 24 25 1. Writing a contract is easy. Just send a transaction containing Data, with no recipient. Add some fuel, and wooo! It's deployed. 26 27 ``` 28 aqua.sendTransaction({from:aqua.coinbase,data:'6060604052341561000f57600080fd5b60b18061001d6000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636ffa1caa146044575b600080fd5b3415604e57600080fd5b606260048080359060200190919050506078565b6040518082815260200191505060405180910390f35b60008160020290509190505600a165627a7a723058208aa56e39b6d6a9caab4b9a9dc5241ea1c56dd40cf77f1c1e66af80c59fef24640029'}) 29 ``` 30 31 2. Writing a secure contract is not easy. Here is a **dangerous overflow**: (Input: `9999999999999999999999999999999999999999999999999999999999999999999999999999` returns `-95792089237316195423570985008687907853269984665640564039457584007913129639938` 32 33 ### Source Code 34 35 **The following is buggy code** 36 37 The above contract was made with solidity language, compiled on the [Remix](https://remix.ethereum.org) browser compiler. 38 39 ``` 40 pragma solidity ^0.4.18; 41 42 contract Double { 43 function double(int a) public pure returns(int) { return 2*a;} // buggy 44 } 45 ``` 46 47 using solc or Remix browser compiler, compiles to bytecode , which is sent in a transaction in the *data* field (no "to" field, or "zero address"): 48 49 ``` 50 6060604052341561000f57600080fd5b60b18061001d6000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636ffa1caa146044575b600080fd5b3415604e57600080fd5b606260048080359060200190919050506078565b6040518082815260200191505060405180910390f35b60008160020290509190505600a165627a7a723058208aa56e39b6d6a9caab4b9a9dc5241ea1c56dd40cf77f1c1e66af80c59fef24640029 51 ``` 52 53 and an ABI, to let us know what functions are available. in this case, `double(int256)` that returns an `int256` 54 55 ``` 56 [ 57 { 58 "constant": true, 59 "inputs": [ 60 { 61 "name": "a", 62 "type": "int256" 63 } 64 ], 65 "name": "double", 66 "outputs": [ 67 { 68 "name": "", 69 "type": "int256" 70 } 71 ], 72 "payable": false, 73 "stateMutability": "pure", 74 "type": "function" 75 } 76 ] 77 78 ```