# Coding Guidelines in JS

### I. To create a new account in your client/app, you need to follow these steps:

1\) Install bip39 library via npm:

```bash
npm install bip39
```

or using CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/bip39@3.1.0/src/index.min.js">
</script>
```

2\) Install @fruitsjs/core, @fruitsjs/crypto via npm:

```bash
npm install @fruitsjs/core
npm install @fruitsjs/crypto
```

3\) Generate your passphrase from bip39:

```javascript
import * as bip39 from 'bip39';
// This is a passphrase according to BIP39 standard.
// Currently we only accept passphrases according to this standard.
const passphraseMnemonic = bip39.generateMnemonic();
```

4\) Generate keys, accountId address from passphrase

```java
import {generateMasterKeys} from '@fruitsjs/crypto';
import {Address} from '@fruitsjs/core';

const keys = generateMasterKeys(passphraseMnemonic);

// This key is used to active account
const publicKey = keys.publicKey;
// This key is used to sign transactions.
const privateKey = keys.signPrivateKey;
const address = Address.fromPublicKey(keys.publicKey, 'FRUITS');

// Account Id: 4397003537557138002
const accountId = address.getNumericId();

// Address: FRUITS-PCLL-FH85-CPEZ-5DC3-UECE-DPK7
const addressRS = address.getReedSolomonAddress();
```

5\) After completing the above steps, you have a new account, but it does not exist in the FRUITS network. You need to call our active service according to the instructions below, then your account can be used.

### II. To activate your account on FRUITS network, you need to follow these steps:

1\) Call API to activator:

* URL: <https://activator.fwallet.net/fruits/activator/active>\
  ( Testnet URL:[ https://testnet-activator.fwallet.net/fruits/activator/active ](< https://testnet-activator.fwallet.net/fruits/activator/active >))
* Method: POST
* Request Body:

```json
{
    "activeRequests": 
    [
        {
            "id": accountId, //generated above
            "publicKey": publicKey //generated above
        }
    ]
}
```

* Response:

```json
{
    "errorCode": 0,
    "message": "",
    "result": null
}
```

➔ errorCode = 0 means there is no error, you have successfully requested.

➔ errorCode = 1 means that an error has occurred, you need to check the information in the message.

2\) After calling API, you need to wait about 2 - 5 minutes for the system to activate the account. After that time, you can check if the account is active or not by calling the following API, if not please contact us:

* URL: <https://fwallet.net/fruits?requestType=getAccount&account=accountId>\
  ( Testnet URL:[ https://testnet.fwallet.net/fruits?requestType=getAccount\&account=accountId](< https://testnet.fwallet.net/fruits?requestType=getAccount\&account=accountId>) )
* Method: GET
* If the response has an errorCode, you have not activated it successfully, please contact us for support.
* Otherwise, if the response has no errorCode, you have created it successfully.


---

# 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://api.fwallet.net/create-and-active-account/coding-guidelines-in-js.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.
