← Back to index

Okay, let's craft a detailed API Reference for your ContextCoin (CTX) program on Solana. This will be a markdown document (API.md) that provides developers with all the necessary information to interact with your smart contracts.

ContextCoin (CTX) Program API Reference

This document provides a detailed API reference for the ContextCoin (CTX) program on the Solana blockchain. It outlines all available instructions, account structures, error codes, and other essential information for developers who wish to interact with the program.

Program ID

The program's deployed address is: <YourProgramIdHere> (Replace this with your actual program ID)

Program-Derived Addresses (PDAs)

This program uses Program-Derived Addresses (PDAs) to securely store program state. The following PDAs are used:

Instructions

This section details each instruction that can be sent to the ContextCoin program. Each instruction is accompanied by a description, input parameters, and account requirements.

1. InitializeIco

{
  "instruction": "InitializeIco",
  "data": {
    "token_mint": "Fgc9gT1Jq9b76T6H9q2YxRj8f9n3k8p7f4s5d6e7c",
    "total_supply": 1000000000,
     "base_price": 10000,
    "scaling_factor": 1000000,
  },
  "accounts": [
    {"account": "4p2aK9W1x1Q9aT5s6d7e8f9g0h1j2k3l4m5n6o7p", "isWritable": true},
    {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isSigner": true},
       {"account": "8o9i7j6k5l4m3n2o1p0q9a8b7c6d5e4f3g2h1", "isWritable": true},
    {"account": "SysvarRent111111111111111111111111111111111", "isSigner": true}
  ]
}

2. BuyTokens

{
  "instruction": "BuyTokens",
  "data": {
    "amount": 100000,
  },
  "accounts": [
       {"account": "4p2aK9W1x1Q9aT5s6d7e8f9g0h1j2k3l4m5n6o7p", "isWritable": false},
    {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isSigner": true, "isWritable": true},
    {"account": "Fgc9gT1Jq9b76T6H9q2YxRj8f9n3k8p7f4s5d6e7c", "isWritable": false},
    {"account": "1s2d3f4g5h6j7k8l9m0n1o2p3q4r5s6t", "isWritable": true},
       {"account": "8o9i7j6k5l4m3n2o1p0q9a8b7c6d5e4f3g2h1", "isWritable": true},
    {"account": "11111111111111111111111111111111", "isWritable": false},
       {"account": "SysvarRent111111111111111111111111111111111", "isSigner": false},
  ]
}

3. SellTokens

{
  "instruction": "SellTokens",
  "data": {
    "amount": 100,
  },
  "accounts": [
       {"account": "4p2aK9W1x1Q9aT5s6d7e8f9g0h1j2k3l4m5n6o7p", "isWritable": true},
    {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isSigner": true, "isWritable": true},
    {"account": "Fgc9gT1Jq9b76T6H9q2YxRj8f9n3k8p7f4s5d6e7c", "isWritable": false},
     {"account": "1s2d3f4g5h6j7k8l9m0n1o2p3q4r5s6t", "isWritable": true},
        {"account": "8o9i7j6k5l4m3n2o1p0q9a8b7c6d5e4f3g2h1", "isWritable": true},
    {"account": "11111111111111111111111111111111", "isWritable": false},
         {"account": "SysvarRent111111111111111111111111111111111", "isSigner": false},

  ]
}

4. WithdrawFromEscrow

{
  "instruction": "WithdrawFromEscrow",
  "data": {
    "amount": 1000,
  },
  "accounts": [
    {"account": "4p2aK9W1x1Q9aT5s6d7e8f9g0h1j2k3l4m5n6o7p", "isWritable": false},
    {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isSigner": true, "isWritable": true},
        {"account": "8o9i7j6k5l4m3n2o1p0q9a8b7c6d5e4f3g2h1", "isWritable": true},
      {"account": "11111111111111111111111111111111", "isWritable": false},
  ]
}

5. CreateResourceAccess

{
  "instruction": "CreateResourceAccess",
  "data": {
      "resource_id": "MyResource1",
    "access_fee": 1,
  },
  "accounts": [
    {"account": "2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q", "isWritable": true},
      {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isSigner": true},
    {"account": "SysvarRent111111111111111111111111111111111", "isSigner": true}
  ]
}

6. AccessResource

{
  "instruction": "AccessResource",
    "data": {
     "resource_id": "MyResource1",
    "amount": 2,
  },
  "accounts": [
        {"account": "2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q", "isWritable": false},
    {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isSigner": true, "isWritable": true},
        {"account": "D3G8a76b5c4d3e2f1g0h9i8j7k6l5m4n3o2p1q", "isWritable": true},
      {"account": "11111111111111111111111111111111", "isWritable": false},
  ]
}

Account Structures

This section describes the data structures of each account used by the ContextCoin program.

1. ICOState

2. ResourceAccessState

Error Codes

This section provides a list of custom error codes that the ContextCoin program may return.

Error Code Description
InsufficientFunds The user does not have enough funds to perform the operation.
InvalidAccountOwner The account owner is not authorized to perform the action.
InvalidInstruction The instruction is not recognized or has invalid data.
InvalidEscrowAccount The escrow account provided does not match the expected address.
InvalidTokenMint The token mint provided is not valid for this operation.
InvalidStateAccount The state account does not match the expected account.
InvalidResource The resource account is invalid or does not match the request.
CalculationOverflow A calculation resulted in an overflow.
EscrowMismatch The escrow account did not match the stored escrow address
NotInitialized The state account has not been initialized

Data Serialization

All instruction data and account state is serialized/deserialized using the Borsh serialization format.

Additional Notes


Key takeaways from this API Reference:

Remember to:

  1. Replace Placeholders: Fill in the actual program ID (<YourProgramIdHere>), token mint addresses, and any other relevant placeholders.
  2. Keep Up-to-Date: As you update your program, be sure to update the API reference accordingly.
  3. Host this Document: Place this API.md in your project repository or documentation website.

This API reference should greatly help developers to interact with your ContextCoin program! Let me know if you need any further assistance.