> For the complete documentation index, see [llms.txt](https://circular-protocol.gitbook.io/hyper-code-ide-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://circular-protocol.gitbook.io/hyper-code-ide-guide/lesson-4-your-first-token/transfer-function.md).

# Transfer Function

The transfer function is likely the most important endpoint, as it handles token transfers between two wallets. Similar to the Drop endpoint, we must carefully manage the order of execution to ensure optimal performance.

```javascript
Transfer: function (to, amount) {
        
       // tests the transfer amount
       if(amount<=0) 
       {
         print("Inproper amount\n");
         return false;
       }
      
       // Createa a new wallet instance
        var From = Object.create(CRC_Wallet); 
      
        // Opens the Sender's wallet
        From.OpenWallet(msg.From);
      
        // If there are enough tokens and the amount is positive
        if (From.Balance >= amount) {
            
            // Create a new wallet instance 
            var To = Object.create(CRC_Wallet); 
          
            // Opens the recipient's wallet
            if(To.OpenWallet(to)){
              
                // Transfers the tokens
                From.Balance -= amount;
                To.Balance   += amount;
              
                //Prints out the message 
                println('Transfered : ' + amount + ', To : "' + To.Address );
              
                // Saves the wallets
                From.CloseWallet();
                To.CloseWallet();
              
                return true;
            } else {
              
                // Invalid Recipient Address
                print("Invalid Recipient\n");
              
                return false;    
            }
        }
      
        print("Transfer failed\n");
      
        return false;
    },
```

Similar to the “Drop” function, the “Transfer” function requires a strategic sequence of operations for efficiency.

First, we check if the transfer amount is greater than zero, avoiding unnecessary wallet access otherwise. We open the sender’s wallet and verify that the balance covers the transfer amount. Once confirmed, we open the recipient’s wallet, ensuring it’s successful.

The transfer is executed by deducting tokens from the sender and crediting the recipient. A message is logged before updating both wallets.

With the transfer function complete, our token is ready for deployment. We’ll now explore common smart contract templates to ensure a smooth start in Circular Protocol development.​


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://circular-protocol.gitbook.io/hyper-code-ide-guide/lesson-4-your-first-token/transfer-function.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
