This project demonstrates how to interact with Marginfi and Solana using JavaScript. It provides examples of creating a Marginfi account, depositing funds into the account, and withdrawing funds from the account.
Before running the code, make sure you have the following prerequisites installed:
- Node.js (version 12 or above)
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/your-username/marginfi-solana-example.git
-
Navigate to the project directory:
cd marginfi-solana-example
-
Install the required dependencies:
npm install
- Create a file named
secret
in the project directory. - Open the
secret
file and paste your private key in base58 format. Make sure there are no extra spaces or newline characters.
To run the example script, use the following command:
node marginfi-example.js
The script will perform the following actions:
- Create a new Marginfi account associated with the provided private key.
- Deposit 1 SOL into the Marginfi account.
- Withdraw 0.5 SOL from the Marginfi account.
Make sure you have sufficient funds in your Solana account associated with the provided private key to cover the transaction fees and the amount being deposited.
Please note that it is crucial to keep your private key secure and never share it publicly. Make sure to store it safely and use appropriate security measures when handling sensitive information like private keys.
This project relies on the following dependencies:
@solana/web3.js
: Solana JavaScript SDK for interacting with the Solana blockchain.@marginfi/core
: Marginfi JavaScript SDK for interacting with Marginfi.bs58
: Library for encoding and decoding base58 strings.
This project is licensed under the MIT License.
This example is provided for educational purposes only. Use it at your own risk. Always exercise caution when working with real funds and ensure that you understand the code and its implications before running it in a production environment.
Feel free to customize the README file based on your specific project details and requirements.