├── .DS_Store ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── SECURITY.md ├── foundry └── erc20 │ ├── .env.example │ ├── .gitattributes │ ├── .gitignore │ ├── .vscode │ └── settings.json │ ├── LICENSE │ ├── README.md │ ├── foundry.toml │ ├── remappings.txt │ ├── script │ └── Acacia.s.sol │ └── src │ └── Acacia.sol ├── hardhat ├── .DS_Store ├── deterministic-deployer-example │ ├── .env.example │ ├── .gitignore │ ├── .prettierrc │ ├── LICENSE │ ├── README.md │ ├── contracts │ │ └── TestToken.sol │ ├── hardhat.config.ts │ ├── package.json │ ├── scripts │ │ └── deploy.ts │ ├── src │ │ └── Deterministic-Deployer.ts │ └── tsconfig.json ├── erc20 │ ├── .DS_Store │ ├── .env.sample │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── contracts │ │ └── WatermelonToken.sol │ ├── hardhat.config.js │ ├── package-lock.json │ ├── package.json │ ├── scripts │ │ └── deploy.js │ ├── tasks │ │ ├── account.js │ │ ├── approve.js │ │ ├── balanceOf.js │ │ ├── totalSupply.js │ │ ├── transfer.js │ │ └── transferFrom.js │ └── yarn.lock ├── greeter-example │ ├── .DS_Store │ ├── .env.sample │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── contracts │ │ └── Greeter.sol │ ├── hardhat.config.js │ ├── package-lock.json │ ├── package.json │ ├── scripts │ │ └── deploy.js │ ├── test │ │ └── sample.test.js │ └── yarn.lock └── incrementer-example │ ├── .DS_Store │ ├── .env.sample │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── contracts │ └── Incrementer.sol │ ├── hardhat.config.js │ ├── package.json │ ├── scripts │ ├── deploy.js │ └── utils.js │ └── yarn.lock └── truffle ├── .DS_Store ├── README.md ├── erc721-example ├── .DS_Store ├── .env.sample ├── .gitignore ├── README.md ├── contracts │ ├── CovidVaccineToken.sol │ └── Migrations.sol ├── images │ └── truffle_nft_example.png ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── package.json ├── test │ └── .gitkeep ├── truffle-config.js └── yarn.lock └── pet-shop-example ├── .DS_Store ├── .env.sample ├── LICENSE ├── README.md ├── box-img-lg.png ├── box-img-sm.png ├── bs-config.json ├── contracts ├── Adoption.sol └── Migrations.sol ├── migrations ├── 1_initial_migration.js └── 2_deploy_contracts.js ├── package.json ├── scripts └── deploy.js ├── src ├── css │ ├── bootstrap.min.css │ └── bootstrap.min.css.map ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 ├── images │ ├── boxer.jpeg │ ├── french-bulldog.jpeg │ ├── golden-retriever.jpeg │ └── scottish-terrier.jpeg ├── index.html ├── js │ ├── app.js │ ├── bootstrap.min.js │ ├── truffle-contract.js │ └── web3.min.js └── pets.json ├── test └── TestAdoption.sol ├── truffle.js └── yarn.lock /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitfinity-network/bitfinity-evm-examples/91de96ea859d62d9db494691ad4a5f0c4d49d791/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "foundry/erc20/lib/forge-std"] 2 | path = foundry/erc20/lib/forge-std 3 | url = https://github.com/foundry-rs/forge-std 4 | [submodule "foundry/erc20/lib/openzeppelin-contracts"] 5 | path = foundry/erc20/lib/openzeppelin-contracts 6 | url = https://github.com/OpenZeppelin/openzeppelin-contracts 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CC0 1.0 Universal 2 | 3 | Statement of Purpose 4 | 5 | The laws of most jurisdictions throughout the world automatically confer 6 | exclusive Copyright and Related Rights (defined below) upon the creator and 7 | subsequent owner(s) (each and all, an "owner") of an original work of 8 | authorship and/or a database (each, a "Work"). 9 | 10 | Certain owners wish to permanently relinquish those rights to a Work for the 11 | purpose of contributing to a commons of creative, cultural and scientific 12 | works ("Commons") that the public can reliably and without fear of later 13 | claims of infringement build upon, modify, incorporate in other works, reuse 14 | and redistribute as freely as possible in any form whatsoever and for any 15 | purposes, including without limitation commercial purposes. These owners may 16 | contribute to the Commons to promote the ideal of a free culture and the 17 | further production of creative, cultural and scientific works, or to gain 18 | reputation or greater distribution for their Work in part through the use and 19 | efforts of others. 20 | 21 | For these and/or other purposes and motivations, and without any expectation 22 | of additional consideration or compensation, the person associating CC0 with a 23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright 24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work 25 | and publicly distribute the Work under its terms, with knowledge of his or her 26 | Copyright and Related Rights in the Work and the meaning and intended legal 27 | effect of CC0 on those rights. 28 | 29 | 1. Copyright and Related Rights. A Work made available under CC0 may be 30 | protected by copyright and related or neighboring rights ("Copyright and 31 | Related Rights"). Copyright and Related Rights include, but are not limited 32 | to, the following: 33 | 34 | i. the right to reproduce, adapt, distribute, perform, display, communicate, 35 | and translate a Work; 36 | 37 | ii. moral rights retained by the original author(s) and/or performer(s); 38 | 39 | iii. publicity and privacy rights pertaining to a person's image or likeness 40 | depicted in a Work; 41 | 42 | iv. rights protecting against unfair competition in regards to a Work, 43 | subject to the limitations in paragraph 4(a), below; 44 | 45 | v. rights protecting the extraction, dissemination, use and reuse of data in 46 | a Work; 47 | 48 | vi. database rights (such as those arising under Directive 96/9/EC of the 49 | European Parliament and of the Council of 11 March 1996 on the legal 50 | protection of databases, and under any national implementation thereof, 51 | including any amended or successor version of such directive); and 52 | 53 | vii. other similar, equivalent or corresponding rights throughout the world 54 | based on applicable law or treaty, and any national implementations thereof. 55 | 56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, 57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and 58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright 59 | and Related Rights and associated claims and causes of action, whether now 60 | known or unknown (including existing as well as future claims and causes of 61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum 62 | duration provided by applicable law or treaty (including future time 63 | extensions), (iii) in any current or future medium and for any number of 64 | copies, and (iv) for any purpose whatsoever, including without limitation 65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes 66 | the Waiver for the benefit of each member of the public at large and to the 67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver 68 | shall not be subject to revocation, rescission, cancellation, termination, or 69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work 70 | by the public as contemplated by Affirmer's express Statement of Purpose. 71 | 72 | 3. Public License Fallback. Should any part of the Waiver for any reason be 73 | judged legally invalid or ineffective under applicable law, then the Waiver 74 | shall be preserved to the maximum extent permitted taking into account 75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver 76 | is so judged Affirmer hereby grants to each affected person a royalty-free, 77 | non transferable, non sublicensable, non exclusive, irrevocable and 78 | unconditional license to exercise Affirmer's Copyright and Related Rights in 79 | the Work (i) in all territories worldwide, (ii) for the maximum duration 80 | provided by applicable law or treaty (including future time extensions), (iii) 81 | in any current or future medium and for any number of copies, and (iv) for any 82 | purpose whatsoever, including without limitation commercial, advertising or 83 | promotional purposes (the "License"). The License shall be deemed effective as 84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the 85 | License for any reason be judged legally invalid or ineffective under 86 | applicable law, such partial invalidity or ineffectiveness shall not 87 | invalidate the remainder of the License, and in such case Affirmer hereby 88 | affirms that he or she will not (i) exercise any of his or her remaining 89 | Copyright and Related Rights in the Work or (ii) assert any associated claims 90 | and causes of action with respect to the Work, in either case contrary to 91 | Affirmer's express Statement of Purpose. 92 | 93 | 4. Limitations and Disclaimers. 94 | 95 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 96 | surrendered, licensed or otherwise affected by this document. 97 | 98 | b. Affirmer offers the Work as-is and makes no representations or warranties 99 | of any kind concerning the Work, express, implied, statutory or otherwise, 100 | including without limitation warranties of title, merchantability, fitness 101 | for a particular purpose, non infringement, or the absence of latent or 102 | other defects, accuracy, or the present or absence of errors, whether or not 103 | discoverable, all to the greatest extent permissible under applicable law. 104 | 105 | c. Affirmer disclaims responsibility for clearing rights of other persons 106 | that may apply to the Work or any use thereof, including without limitation 107 | any person's Copyright and Related Rights in the Work. Further, Affirmer 108 | disclaims responsibility for obtaining any necessary consents, permissions 109 | or other rights required for any use of the Work. 110 | 111 | d. Affirmer understands and acknowledges that Creative Commons is not a 112 | party to this document and has no duty or obligation with respect to this 113 | CC0 or use of the Work. 114 | 115 | For more information, please see 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bitfinity-Examples 2 | 3 | This repository includes DApp boilerplates for [truffle](https://www.trufflesuite.com/), [hardhat](https://hardhat.org/) and [Foundry] () on Bitfinity. These examples cover specific topics: 4 | 5 | - Solidity contract deployment using (Truffle/Hardhat/Foundry). 6 | - Integration with Metamask 7 | - Running DApp on Bitfinity network 8 | 9 | ## Prerequisites 10 | 11 | - Node 12+ 12 | 13 | ## Examples 14 | 15 | - [Truffle](truffle/) 16 | - [Hardhat](hardhat/) 17 | - [Foundry](foundry/) 18 | 19 | More documentation about Bitfinity network can be found [here](https://docs.bitfinity.network/). 20 | 21 | ## Contributing 22 | 23 | Bitfinity team welcomes any kind of contributions in form of bug issues, feature requests, code changes, or documentation enhancement. 24 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /foundry/erc20/.env.example: -------------------------------------------------------------------------------- 1 | MNEMONIC="YOUR_MNEMONIC" 2 | FOUNDRY_PROFILE="default" 3 | PRIVATE_KEY= 4 | BITFINITY_RPC_URL="https://testnet.bitfinity.network" 5 | -------------------------------------------------------------------------------- /foundry/erc20/.gitattributes: -------------------------------------------------------------------------------- 1 | .gas-snapshot linguist-language=Julia 2 | -------------------------------------------------------------------------------- /foundry/erc20/.gitignore: -------------------------------------------------------------------------------- 1 | /cache 2 | /node_modules 3 | /out -------------------------------------------------------------------------------- /foundry/erc20/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "solidity.packageDefaultDependenciesContractsDirectory": "src", 3 | "solidity.packageDefaultDependenciesDirectory": "lib", 4 | "solidity.compileUsingRemoteVersion": "v0.8.20", 5 | "solidity.formatter": "forge", 6 | "search.exclude": { "lib": true }, 7 | "files.associations": { 8 | ".gas-snapshot": "julia" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /foundry/erc20/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Bitfinity Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /foundry/erc20/README.md: -------------------------------------------------------------------------------- 1 | # Foundry 2 | 3 | A Foundry-based ERC20 token deployment. 4 | 5 | ## What's Inside 6 | 7 | - [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart 8 | contracts 9 | - [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing 10 | 11 | If this is your first time with Foundry, check out the 12 | [installation](https://github.com/foundry-rs/foundry#installation) instructions. 13 | 14 | ## Features 15 | 16 | This template builds upon the frameworks and libraries mentioned above, so for details about their specific features, 17 | please consult their respective documentation. 18 | 19 | For example, if you're interested in exploring Foundry in more detail, you should look at the 20 | [Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the 21 | [Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial. 22 | 23 | ### Sensible Defaults 24 | 25 | This template comes with a set of sensible default configurations for you to use. These defaults can be found in the 26 | following files: 27 | 28 | ```text 29 | ├── .gitignore 30 | ├── .solhint.json 31 | ├── foundry.toml 32 | └── remappings.txt 33 | ``` 34 | 35 | ### VSCode Integration 36 | 37 | This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic 38 | Foundation's [Solidity extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity). 39 | 40 | For guidance on how to integrate a Foundry project in VSCode, please refer to this 41 | [guide](https://book.getfoundry.sh/config/vscode). 42 | 43 | ## Usage 44 | 45 | This is a list of the most frequently needed commands. 46 | 47 | ### Build 48 | 49 | Build the contracts: 50 | 51 | ```sh 52 | forge build 53 | ``` 54 | 55 | ### Clean 56 | 57 | Delete the build artifacts and cache directories: 58 | 59 | ```sh 60 | forge clean 61 | ``` 62 | 63 | ### Compile 64 | 65 | Compile the contracts: 66 | 67 | ```sh 68 | forge build 69 | ``` 70 | 71 | ### Coverage 72 | 73 | Get a test coverage report: 74 | 75 | ```sh 76 | forge coverage 77 | ``` 78 | 79 | ### Deploy 80 | 81 | Deploy to Bitfinity testnet : 82 | 83 | ```sh 84 | # To load the variables in the .env file 85 | source .env 86 | forge script script/NFT.s.sol:MyScript --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv 87 | ``` 88 | 89 | For this script to work, you need to have a `MNEMONIC` environment variable set to a valid 90 | [BIP39 mnemonic](https://iancoleman.io/bip39/). 91 | 92 | For instructions on how to deploy to a testnet or mainnet, check out the 93 | [Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial. 94 | 95 | ### Format 96 | 97 | Format the contracts: 98 | 99 | ```sh 100 | forge fmt 101 | ``` 102 | 103 | ### Gas Usage 104 | 105 | Get a gas report: 106 | 107 | ```sh 108 | forge test --gas-report 109 | ``` 110 | 111 | ### Test 112 | 113 | Run the tests: 114 | 115 | ```sh 116 | forge test 117 | ``` 118 | 119 | ## Notes 120 | 121 | 1. Foundry uses [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to manage dependencies. For 122 | detailed instructions on working with dependencies, please refer to the 123 | [guide](https://book.getfoundry.sh/projects/dependencies.html) in the book 124 | 2. You don't have to create a `.env` file, but filling in the environment variables may be useful when debugging and 125 | testing against a fork. 126 | 127 | ## License 128 | 129 | This project is licensed under MIT. 130 | -------------------------------------------------------------------------------- /foundry/erc20/foundry.toml: -------------------------------------------------------------------------------- 1 | [profile.default] 2 | solc = "0.8.20" 3 | bytecode_hash = "none" 4 | optimizer_runs = 1000000 5 | 6 | [profile.intense.fuzz] 7 | runs = 10000 8 | 9 | [fmt] 10 | bracket_spacing = true 11 | int_types = "long" 12 | line_length = 120 13 | multiline_func_header = "all" 14 | number_underscore = "thousands" 15 | quote_style = "double" 16 | tab_width = 4 17 | wrap_comments = true 18 | 19 | 20 | [rpc_endpoints] 21 | bitfinity = "${BITFINITY_RPC_URL}" 22 | -------------------------------------------------------------------------------- /foundry/erc20/remappings.txt: -------------------------------------------------------------------------------- 1 | openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/ -------------------------------------------------------------------------------- /foundry/erc20/script/Acacia.s.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.20; 3 | 4 | import "forge-std/Script.sol"; 5 | import "../src/Acacia.sol"; 6 | 7 | 8 | contract AcaciaScript is Script { 9 | function run() external { 10 | uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); 11 | vm.startBroadcast(deployerPrivateKey); 12 | 13 | Acacia token = new Acacia(10000000000000000000); 14 | 15 | vm.stopBroadcast(); 16 | } 17 | } -------------------------------------------------------------------------------- /foundry/erc20/src/Acacia.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.20; 3 | 4 | import "openzeppelin-contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract Acacia is ERC20 { 7 | constructor(uint256 initialSupply) ERC20("Acacia", "ACA") { 8 | _mint(msg.sender, initialSupply); 9 | } 10 | 11 | function decimals() public pure override(ERC20) returns (uint8) { 12 | return 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /hardhat/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bitfinity-network/bitfinity-evm-examples/91de96ea859d62d9db494691ad4a5f0c4d49d791/hardhat/.DS_Store -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/.env.example: -------------------------------------------------------------------------------- 1 | PRIVATE_KEY= 2 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | #Hardhat files 4 | cache 5 | artifacts 6 | factories 7 | typechain 8 | 9 | yarn.lock 10 | 11 | .env 12 | 13 | typechain/* 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSpacing": true, 4 | "endOfLine":"auto", 5 | "printWidth": 120, 6 | "singleQuote": false, 7 | "tabWidth": 2, 8 | "trailingComma": "all", 9 | "overrides": [ 10 | { 11 | "files": "*.sol", 12 | "options": { 13 | "tabWidth": 4 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/LICENSE: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2023 Bitfinity Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/README.md: -------------------------------------------------------------------------------- 1 | # Deterministic Deployer for Hardhat Example 2 | 3 | This example shows how to deploy a contract to Bitfinity network using deterministic deployer. It uses Arachnid deployer found [here](). 4 | 5 | ## About 6 | 7 | This project is a Hardhat project. It is ready to compile and deploy smart contracts locally and on Bitfinity network. 8 | 9 | It uses: 10 | 11 | - [Hardhat](https://github.com/nomiclabs/hardhat): compile and run the smart contracts on a local development network 12 | - [TypeChain](https://github.com/ethereum-ts/TypeChain): generate TypeScript types for smart contracts 13 | - [Ethers](https://github.com/ethers-io/ethers.js/): renowned Ethereum library and wallet implementation 14 | 15 | ## Usage 16 | 17 | ### Pre Requisites 18 | 19 | Before running any command, make sure to install dependencies: 20 | 21 | ```sh 22 | yarn install 23 | ``` 24 | 25 | ### Compile 26 | 27 | Compile the smart contracts with Hardhat: 28 | 29 | ```sh 30 | yarn compile 31 | ``` 32 | 33 | ### Deploy contract to network 34 | 35 | ```sh 36 | npx hardhat run --network bitfinity ./scripts/deploy.ts 37 | ``` 38 | 39 | ## Thanks 40 | 41 | If you like it than you shoulda put a start ⭐ on it 42 | 43 | ## License 44 | 45 | MIT 46 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/contracts/TestToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | import "@openzeppelin/contracts/access/AccessControl.sol"; 6 | 7 | /** 8 | * @notice A mintable ERC20 9 | */ 10 | contract TestToken is ERC20, AccessControl { 11 | bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); 12 | 13 | constructor() ERC20("Test Token", "TST") { 14 | _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); 15 | _setupRole(MINTER_ROLE, msg.sender); 16 | } 17 | 18 | function mint(address to, uint256 amount) external { 19 | require(hasRole(MINTER_ROLE, msg.sender), "Only minter can mint"); 20 | _mint(to, amount); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import { HardhatUserConfig } from "hardhat/config"; 2 | import "@nomicfoundation/hardhat-toolbox"; 3 | 4 | import { config as dotenvConfig } from "dotenv"; 5 | import { resolve } from "path"; 6 | dotenvConfig({ path: resolve(__dirname, "./.env") }); 7 | 8 | 9 | const PRIVATE_KEY = process.env.PRIVATE_KEY || ""; 10 | 11 | 12 | // You need to export an object to set up your config 13 | // Go to https://hardhat.org/config/ to learn more 14 | const config: HardhatUserConfig = { 15 | defaultNetwork: "hardhat", 16 | networks: { 17 | hardhat: { 18 | }, 19 | bitfinity: { 20 | url: "https://testnet.bitfinity.network", 21 | accounts: ["0x"+ PRIVATE_KEY], 22 | chainId: 355113, 23 | }, 24 | localhost: { 25 | url: "http://127.0.0.1:8545", 26 | accounts: ["0x" + PRIVATE_KEY], 27 | chainId: 355113, 28 | } 29 | }, 30 | solidity: { 31 | compilers: [ 32 | { 33 | version: "0.8.20", 34 | settings: { 35 | optimizer: { 36 | enabled: true, 37 | runs: 200, 38 | }, 39 | }, 40 | }, 41 | ], 42 | }, 43 | typechain: { 44 | outDir: "typechain", 45 | target: "ethers-v5", 46 | }, 47 | }; 48 | 49 | export default config; 50 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deterministic-deployments", 3 | "version": "0.0.3", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "compile": "npx hardhat compile", 8 | "clean": "rm -rf ./artifacts ./cache ./typechain " 9 | }, 10 | "author": "Bitfinity Network", 11 | "license": "MIT", 12 | "devDependencies": { 13 | "@ethersproject/abi": "^5.7.0", 14 | "@ethersproject/providers": "^5.7.1", 15 | "@nomicfoundation/hardhat-chai-matchers": "^1.0.4", 16 | "@nomicfoundation/hardhat-network-helpers": "^1.0.6", 17 | "@nomicfoundation/hardhat-toolbox": "^2.0.0", 18 | "@nomiclabs/hardhat-ethers": "^2.2.0", 19 | "@nomiclabs/hardhat-etherscan": "^3.1.7", 20 | "@typechain/ethers-v5": "^10.1.0", 21 | "@typechain/hardhat": "^6.1.3", 22 | "@types/chai": "^4.2.0", 23 | "@types/mocha": "^10.0.4", 24 | "@types/node": "^18.11.2", 25 | "chai": "^4.3.10", 26 | "dotenv": "^16.3.1", 27 | "ethers": "^5.7.1", 28 | "hardhat": "^2.12.0", 29 | "hardhat-gas-reporter": "^1.0.9", 30 | "solidity-coverage": "^0.8.5", 31 | "ts-node": "^10.9.1", 32 | "typechain": "^8.1.0", 33 | "typescript": "^4.8.4" 34 | }, 35 | "dependencies": { 36 | "@openzeppelin/contracts": "^4.7.3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hardhat/deterministic-deployer-example/scripts/deploy.ts: -------------------------------------------------------------------------------- 1 | // We require the Hardhat Runtime Environment explicitly here. This is optional 2 | // but useful for running the script in a standalone fashion through `node 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /truffle/pet-shop-example/src/js/app.js: -------------------------------------------------------------------------------- 1 | App = { 2 | web3Provider: null, 3 | contracts: {}, 4 | 5 | init: function() { 6 | // Load pets. 7 | $.getJSON('../pets.json', function(data) { 8 | var petsRow = $('#petsRow'); 9 | var petTemplate = $('#petTemplate'); 10 | 11 | for (i = 0; i < data.length; i ++) { 12 | petTemplate.find('.panel-title').text(data[i].name); 13 | petTemplate.find('img').attr('src', data[i].picture); 14 | petTemplate.find('.pet-breed').text(data[i].breed); 15 | petTemplate.find('.pet-age').text(data[i].age); 16 | petTemplate.find('.pet-location').text(data[i].location); 17 | petTemplate.find('.btn-adopt').attr('data-id', data[i].id); 18 | 19 | petsRow.append(petTemplate.html()); 20 | } 21 | }); 22 | 23 | return App.initWeb3(); 24 | }, 25 | 26 | initWeb3: function() { 27 | // Is there an injected web3 instance ? 28 | if (typeof web3 !== 'undefined') { 29 | App.web3Provider = web3.currentProvider; 30 | } 31 | else { 32 | //// If no injected web3 instance is detected, fall back to Ganache 33 | App.web3Provider = new Web3.providers.HttpProvider('http://localhost:8545'); 34 | } 35 | 36 | web3 = new Web3(App.web3Provider); 37 | return App.initContract(); 38 | }, 39 | 40 | initContract: function() { 41 | $.getJSON('Adoption.json', function(data) { 42 | App.contracts.Adoption = TruffleContract(data); 43 | // Set the provider for our contract 44 | App.contracts.Adoption.setProvider(App.web3Provider); 45 | // Use our contract to retrieve and mark the adopted pets 46 | return App.markAdopted(); 47 | }); 48 | 49 | return App.bindEvents(); 50 | }, 51 | 52 | bindEvents: function() { 53 | $(document).on('click', '.btn-adopt', App.handleAdopt); 54 | }, 55 | 56 | markAdopted: function(adopters, account) { 57 | var adoptionInstance; 58 | 59 | App.contracts.Adoption.deployed().then(function(instance) { 60 | adoptionInstance = instance; 61 | return adoptionInstance.getAdopters(); 62 | }).then(function(adopters) { 63 | for (i = 0; i < adopters.length; i++) { 64 | if (adopters[i] !== '0x0000000000000000000000000000000000000000') { 65 | $('.panel-pet').eq(i).find('button').text('Success').attr('disabled', true); 66 | } 67 | } 68 | }).catch(function(err) { 69 | console.log(err.message); 70 | }); 71 | }, 72 | 73 | handleAdopt: function(event) { 74 | event.preventDefault(); 75 | 76 | var petId = parseInt($(event.target).data('id')); 77 | 78 | var adoptionInstance; 79 | 80 | web3.eth.getAccounts(function(error, accounts) { 81 | if (error) { 82 | console.log(error); 83 | } 84 | 85 | var account = accounts[0]; 86 | 87 | App.contracts.Adoption.deployed().then(function(instance) { 88 | adoptionInstance = instance; 89 | 90 | // Execute adopt as a transaction by sending account 91 | return adoptionInstance.adopt(petId, {from: account}); 92 | }).then(function(result) { 93 | return App.markAdopted(); 94 | }).catch(function(err) { 95 | console.log(err.message); 96 | }); 97 | }); 98 | } 99 | }; 100 | 101 | $(function() { 102 | $(window).load(function() { 103 | App.init(); 104 | }); 105 | }); 106 | -------------------------------------------------------------------------------- /truffle/pet-shop-example/src/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.7 (http://getbootstrap.com) 3 | * Copyright 2011-2016 Twitter, Inc. 4 | * Licensed under the MIT license 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>3)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){if(a(b.target).is(this))return b.handleObj.handler.apply(this,arguments)}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.7",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a("#"===f?[]:f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.7",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c).prop(c,!0)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c).prop(c,!1))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target).closest(".btn");b.call(d,"toggle"),a(c.target).is('input[type="radio"], input[type="checkbox"]')||(c.preventDefault(),d.is("input,button")?d.trigger("focus"):d.find("input:visible,button:visible").first().trigger("focus"))}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.7",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));if(!(a>this.$items.length-1||a<0))return this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){if(!this.sliding)return this.slide("next")},c.prototype.prev=function(){if(!this.sliding)return this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.7",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.7",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);if(c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),!c.isInStateTrue())return clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide()},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null,a.$element=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;!e&&/destroy|hide/.test(b)||(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.7",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.7",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.7",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return e=a-d&&"bottom"},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /truffle/pet-shop-example/src/pets.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 0, 4 | "name": "Frieda", 5 | "picture": "images/scottish-terrier.jpeg", 6 | "age": 3, 7 | "breed": "Scottish Terrier", 8 | "location": "Lisco, Alabama" 9 | }, 10 | { 11 | "id": 1, 12 | "name": "Gina", 13 | "picture": "images/scottish-terrier.jpeg", 14 | "age": 3, 15 | "breed": "Scottish Terrier", 16 | "location": "Tooleville, West Virginia" 17 | }, 18 | { 19 | "id": 2, 20 | "name": "Collins", 21 | "picture": "images/french-bulldog.jpeg", 22 | "age": 2, 23 | "breed": "French Bulldog", 24 | "location": "Freeburn, Idaho" 25 | }, 26 | { 27 | "id": 3, 28 | "name": "Melissa", 29 | "picture": "images/boxer.jpeg", 30 | "age": 2, 31 | "breed": "Boxer", 32 | "location": "Camas, Pennsylvania" 33 | }, 34 | { 35 | "id": 4, 36 | "name": "Jeanine", 37 | "picture": "images/french-bulldog.jpeg", 38 | "age": 2, 39 | "breed": "French Bulldog", 40 | "location": "Gerber, South Dakota" 41 | }, 42 | { 43 | "id": 5, 44 | "name": "Elvia", 45 | "picture": "images/french-bulldog.jpeg", 46 | "age": 3, 47 | "breed": "French Bulldog", 48 | "location": "Innsbrook, Illinois" 49 | }, 50 | { 51 | "id": 6, 52 | "name": "Latisha", 53 | "picture": "images/golden-retriever.jpeg", 54 | "age": 3, 55 | "breed": "Golden Retriever", 56 | "location": "Soudan, Louisiana" 57 | }, 58 | { 59 | "id": 7, 60 | "name": "Coleman", 61 | "picture": "images/golden-retriever.jpeg", 62 | "age": 3, 63 | "breed": "Golden Retriever", 64 | "location": "Jacksonwald, Palau" 65 | }, 66 | { 67 | "id": 8, 68 | "name": "Nichole", 69 | "picture": "images/french-bulldog.jpeg", 70 | "age": 2, 71 | "breed": "French Bulldog", 72 | "location": "Honolulu, Hawaii" 73 | }, 74 | { 75 | "id": 9, 76 | "name": "Fran", 77 | "picture": "images/boxer.jpeg", 78 | "age": 3, 79 | "breed": "Boxer", 80 | "location": "Matheny, Utah" 81 | }, 82 | { 83 | "id": 10, 84 | "name": "Leonor", 85 | "picture": "images/boxer.jpeg", 86 | "age": 2, 87 | "breed": "Boxer", 88 | "location": "Tyhee, Indiana" 89 | }, 90 | { 91 | "id": 11, 92 | "name": "Dean", 93 | "picture": "images/scottish-terrier.jpeg", 94 | "age": 3, 95 | "breed": "Scottish Terrier", 96 | "location": "Windsor, Montana" 97 | }, 98 | { 99 | "id": 12, 100 | "name": "Stevenson", 101 | "picture": "images/french-bulldog.jpeg", 102 | "age": 3, 103 | "breed": "French Bulldog", 104 | "location": "Kingstowne, Nevada" 105 | }, 106 | { 107 | "id": 13, 108 | "name": "Kristina", 109 | "picture": "images/golden-retriever.jpeg", 110 | "age": 4, 111 | "breed": "Golden Retriever", 112 | "location": "Sultana, Massachusetts" 113 | }, 114 | { 115 | "id": 14, 116 | "name": "Ethel", 117 | "picture": "images/golden-retriever.jpeg", 118 | "age": 2, 119 | "breed": "Golden Retriever", 120 | "location": "Broadlands, Oregon" 121 | }, 122 | { 123 | "id": 15, 124 | "name": "Terry", 125 | "picture": "images/golden-retriever.jpeg", 126 | "age": 2, 127 | "breed": "Golden Retriever", 128 | "location": "Dawn, Wisconsin" 129 | } 130 | ] 131 | -------------------------------------------------------------------------------- /truffle/pet-shop-example/test/TestAdoption.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.16; 2 | 3 | import "truffle/Assert.sol"; 4 | import "truffle/DeployedAddresses.sol"; 5 | import "../contracts/Adoption.sol"; 6 | 7 | contract TestAdoption { 8 | Adoption adoption = Adoption(DeployedAddresses.Adoption()); 9 | 10 | // Testing the Adopt function 11 | function testUserCanAdoptPet() public { 12 | uint returnedId = adoption.adopt(8); 13 | uint expected = 8; 14 | 15 | Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded."); 16 | } 17 | 18 | // Testing the retrieval of single pet's owner 19 | function testGetAdopterAddressByPetId() public { 20 | // Expected owner is this contract's address 21 | address expected = address(this); 22 | address adopter = adoption.adopters(8); 23 | Assert.equal(adopter, expected, "Owner of pet ID 8 should be recorded."); 24 | } 25 | 26 | // Testing retrieval of all pet owners 27 | function testGetAdopterAddressByPetIdInArray () public { 28 | // Expected owner is this contract 29 | address expected = address(this); 30 | 31 | // Store adopters in memory rather than contract's storage 32 | address[16] memory adopters = adoption.getAdopters(); 33 | 34 | Assert.equal(adopters[8], expected, "Owner of pet ID 8 should be recorded."); 35 | } 36 | } -------------------------------------------------------------------------------- /truffle/pet-shop-example/truffle.js: -------------------------------------------------------------------------------- 1 | const HDWalletProvider = require('@truffle/hdwallet-provider'); 2 | const { default: Web3 } = require('web3'); 3 | const NonceTrackerSubprovider = require('web3-provider-engine/subproviders/nonce-tracker'); 4 | require('dotenv').config(); 5 | const utils = require('web3-utils'); 6 | const MNEMONIC = process.env.MNEMONIC; 7 | const hdWalletStartIndex = 0; 8 | const numberOfAddresses = 3; 9 | 10 | const setupWallet = (url) => { 11 | const wallet = new HDWalletProvider({ 12 | mnemonic: MNEMONIC, 13 | providerOrUrl: url, 14 | numberOfAddresses, 15 | }); 16 | mintAccounts(wallet); // This will mint 1 Native Token to each address 17 | return wallet; 18 | }; 19 | 20 | const mintAccounts = (wallet) => { 21 | const addresses = wallet.addresses; 22 | 23 | for (let i = 0; i < addresses.length; i++) { 24 | const address = addresses[i]; 25 | const amount = utils.toWei('1', 'ether'); 26 | 27 | wallet.sendAsync( 28 | { 29 | method: 'ic_mintNativeToken', 30 | params: [address, amount], 31 | id: 1, 32 | jsonrpc: '2.0', 33 | }, 34 | (_) => {} 35 | ); 36 | } 37 | }; 38 | 39 | module.exports = { 40 | // See 41 | // for more about customizing your Truffle configuration! 42 | networks: { 43 | development: { 44 | host: '127.0.0.1', 45 | port: 8545, 46 | network_id: '*', // Match any network id 47 | }, 48 | bitfinity: { 49 | provider: () => setupWallet('https://testnet.bitfinity.network'), 50 | network_id: '355113', 51 | from: setupWallet('https://testnet.bitfinity.network').addresses[0], 52 | deploymentPollingInterval: 8000, 53 | timeoutBlocks: 500, 54 | confirmations: 10, 55 | }, 56 | local: { 57 | provider: () => setupWallet('http://127.0.0.1:8545'), 58 | network_id: '355113', 59 | from: setupWallet('http://127.0.0.1:8545').addresses[0], 60 | deploymentPollingInterval: 8000, 61 | timeoutBlocks: 500, 62 | disableConfirmationListener: true, 63 | }, 64 | }, 65 | }; 66 | --------------------------------------------------------------------------------