Generate a Token Contract

After creating a token using the Playfix Token API, you need to generate a smart contract for the token, then deploy token smart contract.

To generate a Token contract, you need to connect to MetaMask,. Then send a POST request to /token endpoint, calling the generateContract method.

Generate the contract for a token.

POST https://api.playfix.io/token/<token_name>:generateContract

If the token already has a contract, it will be overwritten by the newly generated contract.

Path Parameters

NameTypeDescription

token_name*

String

An automatically generated token name. This will start with a prefix of "tokens/" followed by a ULID.

Example: tokens/01gfrf15n9hqw3v08sqearsgh9

Headers

NameTypeDescription

Authorization*

String

Bearer <your_access_token>

{
  "contract": {
    "source": {
      "main": "//...",
      "imports": {
      @opengsn/contracts/src/BaseRelayRecipient.sol: "..."
      @opengsn/contracts/src/interfaces/IRelayRecipient.sol: "..."
      @openzeppelin/contracts/access/AccessControl.sol: "..."
      @openzeppelin/contracts/access/IAccessControl.sol: "..."
      @openzeppelin/contracts/governance/utils/IVotes.sol: "..."
      @openzeppelin/contracts/governance/utils/IVotes.sol: "..."
      @openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol: "..."
      @openzeppelin/contracts/interfaces/IERC3156FlashLender.sol: "..."
      @openzeppelin/contracts/security/Pausable.sol: "..."
      @openzeppelin/contracts/token/ERC20/IERC20.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol: "...
      }
    },
    "abi": "[{...}, {...}, {...}, ...]",
    "bytecode": "0x...",
  }
}

Example cURL API Call

curl --request POST \
  --url https://api.playfix.io/token/<token_name>:generateContract \
  --header 'Authorization: Bearer <your_access_token>'

Example Python API Call

import request

token = "<token_name>"

r = requests.post(
    "https://api.playfix.io/token/" + token + ":generateContract",
    headers = {
        "Authorization": "Bearer <your_access_token>"
        }
    )

print(r.text)

This generates a smart contract per your specifications in the token creation or update process.

Response

{
  "contract": {
    "source": {
      "main": "//...",
      "imports": {
      @opengsn/contracts/src/BaseRelayRecipient.sol: "..."
      @opengsn/contracts/src/interfaces/IRelayRecipient.sol: "..."
      @openzeppelin/contracts/access/AccessControl.sol: "..."
      @openzeppelin/contracts/access/IAccessControl.sol: "..."
      @openzeppelin/contracts/governance/utils/IVotes.sol: "..."
      @openzeppelin/contracts/governance/utils/IVotes.sol: "..."
      @openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol: "..."
      @openzeppelin/contracts/interfaces/IERC3156FlashLender.sol: "..."
      @openzeppelin/contracts/security/Pausable.sol: "..."
      @openzeppelin/contracts/token/ERC20/IERC20.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol: "..."
      @openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol: "...
      }
    },
    "abi": "[{...}, {...}, {...}, ...]",
    "bytecode": "0x...",
  }
}

This sample response is compressed.

Response Fields

  • contract- An object containing the details of the smart contract.

    • source- An object containing the source code of the smart contract.

      • main- source code of the main functionalities of the token contract.

      • imports- imported libraries and dependencies of the smart contract.

    • abi: Method names, parameters and arguments, and data types that can be used to interact with a smart contract.

    • bytecode: The token contract in low-level binary.

Generating a token contract again will overwrite the previous contract.

Last updated