Home

Awesome

Prosopo Provider

NOTE: For a development environment, the easiest way to deploy the Prosopo contract and run the Provider node is via the integration repository. The following instructions explain how to set up the repositories manually.

Prerequisites

Development Environment

Setup a contract node

If you are setting up a development environment, run a development node. For example, the Substrate Contracts Node

Deploy the Prosopo Protocol contract

See protocol instructions

Live environment

If you are running in a test or live environment, use a node endpoint of your choice. Make sure you know the contract account of the Prosopo Protocol contract.

Running a Prosopo Provider Node

The following instructions apply to the provider repo.

Install packages

npm install

Populate the Prosopo Provider Config

Place the required variables in the prosopo.config.ts file in the root of the provider repo.

ParamDescription
PROTOCOL_CONTRACT_JSON_ABI_PATHThe path to the protocol JSON file
SUBSTATE_NODE_ENDPOINTThe substrate node endpoint, e.g. ws://localhost:9944
PROTOCOL_CONTRACT_ADDRESSThe protocol contract address
CAPTCHA_SOLVED_COUNTThe number of solved captchas to send to the captcha frontend client
CAPTCHA_UNSOLVED_COUNTThe number of unsolved captchas to send to the captcha frontend client
CAPTCHA_SOLUTION_REQUIRED_SOLUTION_COUNTThe number of captchas required to calculate a solution to an unsolved captcha
CAPTCHA_SOLUTION_WINNING_PERCENTAGEThe threshold percentage that determines whether a solution is found
CAPTCHA_FILE_PATHThe path to the captcha dataset
MONGO_USERNAMEMongoDB username
MONGO_PASSWORDMongoDB password
MONGO_HOSTMongoDB host
MONGO_PORTMongoDB port
DATABASE_NAMEDatabase name
API_BASE_URLBase URL for API, e.g. http://localhost:3000

Config

const config = {
  contract: {
    abi: '<PROTOCOL_CONTRACT_JSON_ABI_PATH>'
  },
  networks: {
    development: {
      endpoint: '<SUBSTATE_NODE_ENDPOINT>', // e.g. ws://127.0.0.1:9944
      contract: {
        address: '<PROTOCOL_CONTRACT_ADDRESS>',
        name: 'prosopo'
      }
    }
  },
  captchas: {
    solved: {
      count: '<CAPTCHA_SOLVED_COUNT>'
    },
    unsolved: {
      count: '<CAPTCHA_UNSOLVED_COUNT>'
    }
  },
  captchaSolutions: {
    requiredNumberOfSolutions: '<CAPTCHA_SOLUTION_REQUIRED_SOLUTION_COUNT>',
    solutionWinningPercentage: '<CAPTCHA_SOLUTION_WINNING_PERCENTAGE>',
    captchaFilePath: '<CAPTCHA_FILE_PATH>',
  },
  database: {
    development: {
      type: 'mongo',
      endpoint: `mongodb://<MONGO_USERNAME>:<MONGO_PASSWORD>@<MONGO_HOST>:<MONGO_PORT>`,
      dbname: '<DATABASE_NAME>',
    }
  },
  assets : {
    absolutePath: '',
    basePath: ''
  },
  server : {
    baseURL: '<API_BASE_URL>',
  }
}

Run the Provider server

Set a provider mnemonic in prosopo.config.js

Please note your PROVIDER_MNEMONIC environment variable must be set. You can check this with echo $PROVIDER_MNEMONIC

In a development environment, it's easiest to use a development mnemonic as they already have funds. So choose one of //Alice, //Bob, //Ferdie, etc.

    export PROVIDER_MNEMONIC=//Ferdie

You can now register as a Provider in the protocol contract either via the command line.

Register using the Command Line

Try registering a provider on the command line.

npm run cli provider_register -- \
--fee 10 \
--origin https://localhost:8282 \
--payee Provider \
--address YOUR_PROVIDER_ADDRESS

Send a stake (value) and/or update one of the values previously set when registering (fee, origin. payee).

npm run cli provider_update -- \
--fee 10 \
--origin https://localhost:8282 \
--payee Provider \
--address YOUR_PROVIDER_ADDRESS \
--value 10

Verify that your provider was registered by calling the /v1/prosopo/providers/ endpoint or by checking in Polkadot Apps local node.

Curl

curl --location --request GET '127.0.0.1:3000/v1/prosopo/providers/'
{"accounts":["YOUR PROVIDER ADDRESS"]}

Polkadot Apps

Using Polkadot apps

  1. Click Add an existing contract
  2. Enter the contract address and click to select the prosopo.json file in the artifacts folder as the contract ABI
  3. Expand the contract to see the current value of getProviders. It should be ["YOUR PROVIDER ADDRESS"].

Command Line Interface

Please note your PROVIDER_MNEMONIC environment variable must be set. You can check this with echo $PROVIDER_MNEMONIC

Register a provider

npm run cli -- provider_register --fee=10 --origin=https://localhost:8282 --payee=Provider --address ADDRESS
ParamDescription
feeThe amount the Provider charges or pays per captcha approval / disapproval
originThe location of the Provider's service
payeeWho is paid on successful captcha completion (Provider or Dapp)
addressAddress of the Provider

Update a provider and optionally stake

npm run cli -- provider_update --fee=10 --origin=https://localhost:8282 --payee=Provider --address ADDRESS --value STAKE_VALUE

Params are the same as provider_register with the addition of value

ParamDescription
valueThe amount of funds to stake in the contract

Add a dataset for a Provider

npm run cli -- provider_add_data_set --file /usr/src/data/captchas.json
ParamDescription
fileJSON file containing captchas

File format can be viewed here.

De-register a Provider

npm run cli -- provider_deregister --address ADDRESS
ParamDescription
addressAddress of the Provider

Unstake funds

npm run cli -- provider_unstake --value VALUE
ParamDescription
valueThe amount of funds to unstake from the contract

List Provider accounts in contract

npm run cli -- provider_accounts

Other commands

A full list of CLI commands can be viewed by running

npm run cli -- --help

API

Run the Provider API server and image server

npm run start

The API contains methods required by the frontend captcha interface.

API ResourceFunctionTypeParameters
/v1/prosopo/random_provider/:userAccount/:dappContractAccountGet a random provider based on AccountIdGETuserAccount, dappContractAccount
/v1/prosopo/providers/Get list of all provider IDsGET
/v1/prosopo/dapps/Get list of all dapp IDsGET
/v1/prosopo/provider/:providerAccountGet details of a specific Provider accountGETproviderAccount
/v1/prosopo/provider/captcha/:datasetId/:userAccount/:dappContractAccount/:blockNumberGet captchas to solveGETdatasetId, userAccount, dappContractAccount, blockNumber
/v1/prosopo/provider/solutionSubmit captcha solutionsPOSTuserAccount, dappAccount, requestHash, captchas, blockHash, txHash

Tests

You can run the Provider integration tests using the command npm run test. This will start a substrate container containing a predeployed prosopo protocol contract and dapp-example contract. An in-memory mongo database will be used.

To run the tests with coverage stats use:

npx c8 npm run test