# Setup an Actor

This instruction explain how to be an actor  Fair Math Computer. More details about actors can be found [here](https://docs.fairmath.xyz/fhe-computer/fair-math-actors).

Follow provided steps to run your own actor for FHE Computer.

### Prerequisites

1. Get the actor execution file:\
   [Mac OS darwin-amd64 ](https://fairmath-releases.s3.eu-central-1.amazonaws.com/faimrathd/v0.0.20/fairmathd-darwin-amd64.zip)\
   [Mac OS darwin-arm64 ](https://fairmath-releases.s3.eu-central-1.amazonaws.com/faimrathd/v0.0.20/fairmathd-darwin-arm64.zip)\
   [Linux amd64](https://fairmath-releases.s3.eu-central-1.amazonaws.com/faimrathd/v0.0.20/fairmathd-linux-amd64.zip)\
   [Linux arm64](https://fairmath-releases.s3.eu-central-1.amazonaws.com/faimrathd/v0.0.20/fairmathd-linux-arm64.zip)
2. Install fairmath certificate to `/etc/ssl/certs`

{% file src="<https://90165124-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmHu1qRdgJeHeQup4pe3R%2Fuploads%2FjWwDs57gFlJ0yy8eLqHL%2Ffairmath.crt?alt=media&token=8013499a-9472-4be7-aed3-bdc445f9e728>" %}

### Setup&#x20;

1. Create an account in the Fairmath Testnet
   1. Run init command&#x20;

      ```bash
      $ ./fairmathd-linux-amd64 init <username> --chain-id fairmath-tn1
      ```

      Update the `.fairmath/config/client.toml` file with the following fields:

      ```bash
      node = "https://testnet.computer.fairmath.xyz"
      chain-id = "fairmath-tn1"
      keyring-backend = "test"
      ```
   2. Create a Fairmath Net account

      ```bash
      $ ./fairmathd-linux-amd64 keys add <accountname> --keyring-backend=test
      ```

      Note that keyring backend test will store your private key in the open file, never use this option for mainnet
   3. Ask someone to send several tokens for your, it could be done via command

      ```bash
      $ ./fairmathd-linux-amd64 tx bank send <from address> <to address> 100fmth --from <from account> --chain-id fairmath-tn1 --keyring-backend test 
      ```

      You can use `--gas-adjustment` flag or perform transaction in dry-run mode to estimate needed gas value

      Validate your token’s amount:

      ```bash
      $ ./fairmathd-linux-amd64 q bank balances <your address> --chain-id fairmath-tn1
      ```
2. Register actor
   1. Run a transaction to register your actor:

      ```bash
      $ ./fairmathd-linux-amd64 actor register <actorname> --from=<account name or address> --keyring-backend=test
      ```

      `actorname` - is an actor human readable name, just string

      `account name or address` - account name from step 2.b

      if everything is ok then you should see the message like this:

      ```bash
      $ ./fairmathd-linux-amd64 actor register testactor --from=testaccount --keyring-backend=test
      2024/11/04 15:29:10 registration is done: actor 'testactor' is registered under ID: <30>
      ```

      Also an actor config file template will be created in the `~/.faitmath`. Config file name contains actor name and ID, so in the example below it should be `~/.fairmath/testactor-30.yaml` with the following content:

      ```yaml
      actor-id: 30
      tx:
          owner: ""
          gas-adjustment: 1.5
      query:
          query-grpc-address: ""
      orders:
          acquire-interval: 30s
          main-actor-ping: 1m0s
          backup-actor-ping: 1m0s
          min-price: 0fmth
          backup-min-price: 0fmth
      ext-storage:
          ipfs:
              node-url: <http://ipfs/url:8080>
      interpreter:
          path: /path/to/interpreter
      ```

      You have to specify some settings to run actor:

      * `owner` - your account name from step 2.b
      * `query-grpc-address` - grpc address of validator, should be `testnet.computer.fairmath.xyz:9090`
      * `ipfs.node-url` - address for IPFS node, kubo rpc should be available (our IPFS node - `167.235.197.94:5001`)
      * `min-price` and `backup-min-price` - Set the minimum price for which your actor will perform the job.
      * `interpreter` - path to FHE virtual machine

      Also you should add a custom code component which is `18446744073709551615`

      Example of the config:

      ```yaml
      actor-id: 1
      tx:
          owner: "testaccount"
          gas-adjustment: 1.5
      query:
        query-grpc-address: "testnet.computer.fairmath.xyz:9090"
      orders:
          acquire-interval: 30s
          main-actor-ping: 1m0s
          backup-actor-ping: 1m0s
          min-price: 0fmth
          backup-min-price: 0fmth
      ext-storage:
          ipfs:
            node-url: 167.235.197.94:5001
      interpreter:
          path: /home/path/to/vm

      ```
3. Your are ready to run your own actor, please run the command

   ```yaml
   $ ./fairmathd-linux-amd64 actor run <actor config name> --keyring-backend=test 
   ```

   Note that you should NOT specify the full path to the actor config, just place the config file name, e.g. `testactor-30.yaml`. If you see logs then everything is ok:

   ```yaml
   {"level":"warn","time":"2024-11-04T16:00:40+03:00","message":"heavy objects cache could not find the state file(cache will be reset): read cache state: open /home/gsm/yasha/dcomp/fairnet/bin/.actor/fhevm-store/actor-30/h-cache.json: no such file or directory"}
   {"level":"warn","time":"2024-11-04T16:00:50+03:00","message":"failed to acquire order send tx calculate gas: simulate tx: rpc error: code = Unknown desc = rpc error: code = Unknown desc = failed to execute message; message index: 0: acquire order tx: no available orders [cosmos/cosmos-sdk@v0.50.10/baseapp/baseapp.go:1023] with gas used: '36614': unknown request"}
   ```
