> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openformat.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Transfer ERC-20

> Transfer ERC-20 tokens to users in your application. This endpoint (previously known as "Credit") enables you to reward users with ERC-20 tokens for their actions or achievements. The endpoint returns an [unsigned transaction](/api-reference/architecture/transaction-lifecycle) that needs to be signed using your application's private key (stored securely in server environment variables). After signing, you can broadcast the transaction using either:

- [Execute Transaction](/api-reference/endpoint/transactions/post-transactionsexecute) endpoint for immediate submission
- [Execute Transaction and Wait](/api-reference/endpoint/transactions/post-transactionsexecuteandwait) endpoint if you need to wait for transaction confirmation

**Important Notes:**

1. **Default Behavior**: By default, this endpoint transfers existing ERC-20 tokens from the transaction sender's account to the receiver's account through the Application contract specified in the `app_id` parameter.

2. **Required Setup**: Before using this endpoint, you must create an allowance for the Application contract to transfer the required amount of tokens. This can be done using the [approve endpoint](/api-reference/endpoint/credit/post-creditapprove).

3. **Minting Option**: If you want to mint new tokens instead of transferring existing ones, set the optional parameter `mint` to `true`.


<ResponseExample>
  ```json 200 theme={null}
  {
    "success": true,
    "unsignedTransaction": {
      "to": "0x3f0431f04c76623481d5a27056174d550cff5e55",
      "data": "0x609512c90000000000000000000000008102a11ecb4f81da915e1d21b2e525d0a67e83b3012dc3a010c7d01b50e0d17dc79e0b646865725f6a756d7000000000000000000000000000000000000000000000414354494f4e0000000000000000000000000000000000000000000000",
      "maxPriorityFeePerGas": "1020840008",
      "maxFeePerGas": "1035102698",
      "gas": "99572",
      "gasLimit": "99572",
      "nonce": 36,
      "chainId": 31337,
      "type": 2
    }
  }
  ```

  ```json 400 theme={null}
  {
    "success": false,
    "error": {
      "code": "validation_error",
      "message": "Some parameters are invalid",
      "issues": [
        {
          "code": "too_small",
          "message": "Number must be greater than 0",
          "parameter": "amount",
          "path": "amount"
        }
      ]
    }
  }
  ```

  ```JSON 404 theme={null}
  {
    "success": false,
    "error": {
      "code": "token_not_found",
      "message": "Credit token not found"
    }
  }
  ```

  ```JSON 500 theme={null}
  {
    "success": false,
    "error": {
      "code": "transaction_error",
      "message": "There was an error in the blockchain transaction",
      "transaction_error": {
        "reason": "Error: ERC20Base__InsufficientAllowance() ",
        "message": "The contract function \"transferERC20\" reverted with the following signature:\n0x01c2999e. Error: ERC20Base__InsufficientAllowance() ",
        "detailsMessage": "Error: ERC20Base__InsufficientAllowance() Contract Call:   address:   0x3f0431f04c76623481d5a27056174d550cff5e55\n  function:  transferERC20(address _token, address _to, uint256 _amount, bytes32 _id, bytes32 _activityType, string _uri)\n  args:                   (0x8102a11ecb4f81da915e1d21b2e525d0a67e83b3, 0x70997970c51812dc3a010c7d01b50e0d17dc79c8, 1000000000000000000, 0x6f746865725f6a756d7000000000000000000000000000000000000000000000, 0x414354494f4e0000000000000000000000000000000000000000000000000000, )\n  sender:    0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
        "contract_address": "0x3f0431f04c76623481d5a27056174d550cff5e55",
        "chain_id": 31337,
        "function_name": "transferERC20"
      }
    }
  }
  ```
</ResponseExample>


## OpenAPI

````yaml post /reward/credit
openapi: 3.0.0
info:
  version: 0.1.0
  title: Openformat API
servers:
  - url: https://api.openformat.tech/v1
    description: Live server
security:
  - ApiKeyAuth: []
paths:
  /reward/credit:
    post:
      tags:
        - Triggers, Credit
      description: Trigger Credit reward
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                chain:
                  type: string
                  minLength: 1
                  maxLength: 255
                  description: Blockchain network to use
                  example: arbitrum-sepolia
                action_id:
                  type: string
                  minLength: 1
                  maxLength: 32
                  description: Action Id
                  example: dragon_slayed
                receiver:
                  type: string
                  pattern: ^(0x)?[0-9a-fA-F]{40}$
                  description: Ethereum addres of the receiver
                  example: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
                app_id:
                  type: string
                  pattern: ^(0x)?[0-9a-fA-F]{40}$
                  description: Ethereum address of the application
                  example: '0x9716fb655f2a72b1fc1b4db02b8ad20b6747442a'
                token_address:
                  type: string
                  pattern: ^(0x)?[0-9a-fA-F]{40}$
                  description: Ethereum address of the Credit token
                  example: '0xd1f09c70f6f2838a3ab6209c1465af68594667ec'
                amount:
                  type: number
                  minimum: 0
                  exclusiveMinimum: true
                  description: Amount of tokens to reward
                  example: 123
                mint:
                  type: boolean
                  default: false
                  description: >-
                    Whether to mint the Credit tokens instead of doing a
                    transfer
                  example: false
              required:
                - chain
                - action_id
                - receiver
                - app_id
                - token_address
                - amount
      responses:
        '200':
          description: Rewards Credit token
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    enum:
                      - true
                    description: Success response
                    example: true
                  unsignedTransaction:
                    nullable: true
                    description: Unsigned transaction object for the user to sign
                required:
                  - success
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      issues:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                              description: Error code for the field
                              example: invalid_type
                            path:
                              type: array
                              items:
                                type: string
                              description: Field with error
                              example:
                                - some_field
                            message:
                              type: string
                              description: Error message
                              example: Required
                          required:
                            - code
                            - path
                            - message
                        description: Error object with all validation issues
                    required:
                      - issues
                required:
                  - error
        '404':
          description: Credit token not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - failed
                    description: Failed reponse status
                    example: failed
                  error:
                    type: string
                    description: Error message
                    example: No Token found
                required:
                  - status
                  - error
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````