# Truffle

### Truffle <a href="#using-truffle" id="using-truffle"></a>

### Setting up the development environment <a href="#using-truffle" id="using-truffle"></a>

There are a few technical requirements before we start. Please install the following: Requirements:

* Windows, Linux or Mac OS X
* [Node.js v8.9.4 LTS or later](https://nodejs.org/en/)
* [Git](https://git-scm.com/)

**Recommendations for Windows**

If you're running Truffle on Windows, you may encounter some naming conflicts that could prevent Truffle from executing properly. Please see the section on resolving naming conflicts for solutions.

### Installing <a href="#installing" id="installing"></a>

Once we have those installed, we only need one command to install Truffle:

```
npm install -g truffle
```

To verify that Truffle is installed properly, type **`truffle version`** on a terminal. If you see an error, make sure that your npm modules are added to your path.

### Create A Project <a href="#create-a-project" id="create-a-project"></a>

The first step is to create a Truffle project. We'll use the \*DogeRisu as an example, which creates a token that can be transferred between accounts:

* Create a new directory for your Truffle project

```
mkdir DogeRisu
cd DogeRisu
```

* Intialize your project:

```
truffle init
```

Once this operation is completed, you'll now have a project structure with the following items:

* contracts/: Directory for Solidity contracts
* migrations/: Directory for scriptable deployment files
* test/: Directory for test files for testing your application and contracts
* truffle-config.js: Truffle configuration file

#### Create Contract <a href="#create-contract" id="create-contract"></a>

You can write your own smart contract or download the RC20 token smart contract template.

#### Compile Contract <a href="#compile-contract" id="compile-contract"></a>

To compile a Truffle project, change to the root of the directory where the project is located and then type the following into a terminal:

```
truffle compile
```

#### Config Truffle for TC <a href="#config-truffle-for-tc" id="config-truffle-for-tc"></a>

* Go to truffle-config.js
* Update the truffle-config with nc-network-crendentials.

```
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard RISU port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    testnet: {
      provider: () => new HDWalletProvider(mnemonic, `https://api.testnetrisu.com`),
      network_id: 14441,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    bsc: {
      provider: () => new HDWalletProvider(mnemonic, `https://api.risuscan.com`),
      network_id: 15551,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "^0.6.12", // A version or constraint - Ex. "^0.5.0"
    }
  }
}
```

Notice, it requires mnemonic to be passed in for Provider, this is the seed phrase for the account you'd like to deploy from. Create a new .secret file in root directory and enter your 12 word mnemonic seed phrase to get started. To get the seedwords from metamask wallet you can go to Metamask Settings, then from the menu choose Security and Privacy where you will see a button that says reveal seed words.

### Deploying on RISU Network <a href="#deploying-on-loop-network" id="deploying-on-loop-network"></a>

Run this command in root of the project directory:

```
$ truffle migrate --network testnet
```

Contract will be deployed on Risu Chain Testnet, it look like this:

```
1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xaf4502198400bde2148eb4274b08d727a17080b685cd2dcd4aee13d8eb954adc
   > Blocks: 3            Seconds: 9
   > contract address:    0x81eCD10b61978D9160428943a0c0Fb31a5460466
   > block number:        3223948
   > block timestamp:     1604049862
   > account:             0x623ac9f6E62A8134bBD5Dc96D9B8b29b4B60e45F
   > balance:             6.24574114
   > gas used:            191943 (0x2edc7)
   > gas price:           20 gwei
   > value sent:          0 RISU
   > total cost:          0.0000383886 RISU

   Pausing for 5 confirmations...
   ------------------------------
   > confirmation number: 2 (block: 3223952)
   > confirmation number: 3 (block: 3223953)
   > confirmation number: 4 (block: 3223954)
   > confirmation number: 6 (block: 3223956)

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.0000383886 RISU


Summary
=======
> Total deployments:   1
> Final cost:          0.00383886 RISU
```

Remember your address, transaction\_hash and other details provided would differ, Above is just to provide an idea of structure.

**Congratulations!** You have successfully deployed RC20 Smart Contract. Now you can interact with the Smart Contract.

You can check the deployment status here: <https://risuscan.com/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://risu.gitbook.io/risu-ecosystem/whitepaper-2.0-documentation/contract-deployment/truffle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
