@latticexyz/persona-mint

1.2.0 • Public • Published

mint-api

This repo contains a module for minting of Personas via a whitelist key.

  • src/api -- minting api that verifies a whitelist key and signs a message
  • src/eth -- smart contract that gets called to perform the actual mint on behalf of the caller if a valid signed message is provided

Deployment

Each command deploys the contract and publishes the API. Depending on the command, this is deployed either to the production or staging environment.

  • yarn deploy:staging -- deploys to staging environment, updates deployment.json
  • yarn deploy:production -- deploys to production environment, updates deployment.json

Currently

  • staging -- Kovan Testnet, ChainId 42
  • production -- Gnosis Chain, ChainId 100

GSN

The PersonaMinter contract is GSN-compatible. The src/eth directory contains a AcceptEverythingPaymaster.sol contract that can be deployed on a chain via the gsn:deploy-paymaster task, given that there is a HubRelay that can be connected and the paymaster funded.

Once the Paymaster is deployed and it's relay hub and trusted forwarder are set, it has to be funded. The easiest way to do this is by calling the depositFor function on the corresponding RelayHub contract and specifying the target (address) i.e. the address of the deployed paymaster from previous step and the amount to fund the paymaster with. If not using CLI, one way to do this is to go on etherscan.io, connect wallet and call the function. You can call the balanceOf view function on the RelayHub contract to view the balance for the paymaster.

To get info on the deployed RelayHub contract such as where it is deployed, you can checkout the GSN docs, for instance here is the page for the Kovan Testnet.

Testing

  • yarn hardhat:test -- run smart contract tests as well as an end-to-end test of the minting persona flow by calling API to get a singed message and then calling the smart contract. Note: this requires a local running API, so you should run yarn api:dev in another window to start up the API.

Environment Variables

  • Contract-side, we need

    • DEPLOYER_PK -- private key of deployer to deploy the PersonaMinter contract to L1
    • MINT_SIGNER_ADDRESS -- address of the "mint signer" i.e. of the API server signing requests to mint with a whitelist key
    • RPC_KOVAN -- RPC url for the Kovan testnet (current network used for staging environment)
  • API-side, we need (these should be configured on the Cloudflare Worker project settings page)

    • MINTER_PRIVATE_KEY -- private key of the address of the "mint signer" i.e. of the API server signing requests to mint with a whitelist key
    • MINTER_SALT -- salt for the API server signing requests

API

There are two routes exposed for working with the API:

  • /mint
    • POST request
    • Requires body in format of {"minterAddress": <YOUR_ADDRESS>, "whitelistKey": <YOUR_WHITELIST_KEY> }
  • /isvalid/:key
    • GET request
    • key is a variable

The API uses a KV store to store valid whitelist keys. The easiest way to interract with the KV store is via the wrangler command line tool as an admin after authenticated. For example, to insert a key-value into a specific store:

wrangler kv:key put --namespace-id=<ID_OF_KV_STORE> <KEY> <VALUE>

There is more documentation here.

A KV store has a "preview" which can be used for debugging / local testing purposes. Just subsitute the --namespace-id to the preview id of the KV store.

Readme

Keywords

none

Package Sidebar

Install

npm i @latticexyz/persona-mint

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

1.11 MB

Total Files

6

Last publish

Collaborators

  • holic
  • alvarius
  • andriidski
  • l_udens