TAGS

rsk-react-box

CREATED

UPDATED

STARS

INSTALL

...

REPOSITORY
GitHub Download
Please wait: Fetching readme...

b'# RSK React Truffle Box\n\nThis box comes with everything you need to start using smart contracts from a react app on RSK Network. This box was ported and adapted from [React Truffle Box](https://github.com/truffle-box/react-box) to RSK.\n\n## Installation\n\nFirst ensure you are in a new and empty directory.\n\n1. Run the `unbox` command via `npx` and skip to step 3. This will install all necessary dependencies. A Create-React-App is generated in the `client` directory.\n ```js\n npx truffle unbox rsksmart/rsk-react-box\n ```\n\n2. Alternatively, you can install Truffle globally and run the `unbox` command.\n ```javascript\n npm install -g truffle\n truffle unbox rsksmart/rsk-react-box\n ```\n\n3. Run the development console.\n ```javascript\n truffle develop\n ```\n\n4. Compile and migrate the smart contracts. Note inside the development console we don\'t preface commands with `truffle`.\n ```javascript\n compile\n migrate\n ```\n\n5. In the `client` directory, we run the React app. Smart contract changes must be manually recompiled and migrated.\n ```javascript\n // in another terminal (i.e. not in the truffle develop prompt)\n cd client\n npm run start\n ```\n\n6. Truffle can run tests written in Solidity or JavaScript against your smart contracts. Note the command varies slightly if you\'re in or outside of the development console.\n ```javascript\n // inside the development console.\n test\n\n // outside the development console..\n truffle test\n ```\n\n7. Jest is included for testing React components. Compile your contracts before running Jest, or you may receive some file not found errors.\n ```javascript\n // ensure you are inside the client directory when running this\n npm run test\n ```\n\n8. To build the application for production, use the build script. A production build will be in the `client/build` folder.\n ```javascript\n // ensure you are inside the client directory when running this\n npm run build\n ```\n## RSK\n\n### Setup an account & get R-BTC\n\n- Get an address using [these instructions](https://developers.rsk.co/rsk/architecture/account-based/ "Account Based RSK Addresses - RSK Developers Portal").\n- For the RSK Testnet, get tR-BTC from [our faucet](https://faucet.testnet.rsk.co/).\n- For the RSK Mainnet, get R-BTC from [an exchange](https://developers.rsk.co/rsk/rbtc/).\n\n### Setup the gas price\n\n**Gas** is the internal pricing for running a transaction or contract. When you send tokens, interact with a contract, send RBTC, or do anything else on the blockchain, you must pay for that computation. That payment is calculated as gas. In RSK, this is paid in **R-BTC**.\nThe **minimumGasPrice** is written in the block header by miners and establishes the minimum gas price that a transaction should have in order to be included in that block.\n\nTo get the **minimumGasPrice** do the following steps:\n1. Run this query using cURL:\n\n **Mainnet**\n\n ```shell\n curl https://public-node.rsk.co/ \\\n -X POST -H "Content-Type: application/json" \\\n --data \'{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}\'\n ```\n\n **Testnet**\n\n ```shell\n curl https://public-node.testnet.rsk.co/ \\\n -X POST -H "Content-Type: application/json" \\\n --data \'{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}\'\n ```\n\n2. Find in the result the field **_minimumGasPrice_**\n\nFor more information about the **Gas** and **minimumGasPrice** please go [here](https://developers.rsk.co/rsk/rbtc/gas/ "Gas - RSK Developers Portal").\n\n### Connect to RSK\n\n1. Copy your mnemonic to `truffle-config.js`\n\n ```javascript\n // truffle-config.json\n\n const HDWalletProvider = require(\'@truffle/hdwallet-provider\');\n\n //Put your mnemonic here, be careful not to deploy your mnemonic into production!\n const mnemonic = \'A_MNEMONIC\';\n ```\n Please be aware that we are using `HDWalletProvider` with RSK Networks derivations path:\n - RSK Mainnet dpath: `m/44\xe2\x80\x99/137\xe2\x80\x99/0\xe2\x80\x99/0`\n - RSK Testnet dpath: `m/44\xe2\x80\x99/37310\xe2\x80\x99/0\xe2\x80\x99/0`\n\n For more information check [RSKIP57](https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP57.md).\n\n2. Check the gas price of the network, and update `truffle-config.js` if necessary.\n\n3. Run the development console for any RSK network.\n\n ```shell\n # Console for Mainnet\n truffle console --network mainnet\n\n # Console forn Testnet\n truffle console --network testnet\n ```\n\n4. Compile and migrate the smart contracts. Note that inside the development console, we don\'t preface commands with truffle.\n\n ```shell\n compile\n migrate\n ```\n\n**Then continue from step 5 of [installation steps](#installation)**\n'