# Using Truffle

1\. Install truffle (preferably v5.3.0+, sometimes with v5.1.33, `@truffle/hdwallet-provider` does not work)

```
npm install -g truffle
```

2\. Create a metacoin project, unbox metacoin truffle box, and install `@truffle/hdwallet-provider`

```
mkdir metacoin
cd metacoin
truffle unbox metacoin
npm install --save-dev @truffle/hdwallet-provider
```

3\. Modify `truffle-config.js` to add Harmony networks. Make sure to add your mnemonic or private key.

```
const HDWalletProvider = require('@truffle/hdwallet-provider');
const mnemonic = '<ADD-YOUR-MNEMONIC-HERE>';
const privateKeyTest = '<ADD-YOUR-PRIVATE-KEY-HERE>';

module.exports = {
  networks: {
    testnet: {
      provider: () => {
        return new HDWalletProvider({
          mnemonic,
          providerOrUrl: 'https://api.s0.b.hmny.io', // https://api.s0.t.hmny.io for mainnet
          derivationPath: `m/44'/1023'/0'/0/`
        });
      },
      network_id: 1666700000, // 1666600000 for mainnet
    },
    testnetHar: {
      provider: () => {
        if (!privateKeyTest.trim()) {
          throw new Error(
            'Please enter a private key with funds, you can use the default one'
          );
        }
        return new HDWalletProvider({
          privateKeys: [privateKeyTest],
          providerOrUrl: 'https://api.s0.b.hmny.io',
        });
      },
      network_id: 1666700000,
    },
  },
  compilers: {
    solc: {
      version: "0.8.13", // Fetch exact version from solc-bin
    }
  }
};
```

4\. Compile and deploy

```
truffle compile
truffle deploy --network testnet
```


---

# 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://docs.harmony.one/home/developers/deploying-on-harmony/using-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.
