@moonup/moon-sdk
@moonup/moon-sdk Package Documentation
About Moon SDK:
The @moonup/moon-sdk package is a comprehensive SDK that provides easy access to various blockchain functionalities. It supports multiple chains such as Ethereum, Solana, Bitcoin, Cosmos, EOS, Litecoin, Ripple, Tron, Bitcoincash, and Dogecoin. The SDK includes functionalities for managing accounts, interacting with DeFi protocols like Aave, Uniswap, and Yearn, and working with NFTs (ERC-20, ERC-721, and ERC-1155).
Installing Moon SDK:
To utilize the Moon SDK package, first install it to the desired directory of the project:
To install Moon SDK:
Usage
Here's a basic example of how to use the SDK:
Events
The MoonSDK class emits various events that you can listen to in order to handle specific actions or errors. Here's an example of how to listen to events:
The available events are:
accountCreated
: Emitted when a new account is created.transactionSigned
: Emitted when a transaction is signed.messageSigned
: Emitted when a message is signed.typedDataSigned
: Emitted when typed data is signed.transactionSent
: Emitted when a transaction is sent.chainsFetched
: Emitted when the list of supported chains is fetched.chainFetched
: Emitted when a specific chain is fetched.error
: Emitted when an error occurs.
API Reference
MoonSDK Class
Constructor
config
(optional): Configuration object for the SDK.apiKey
(string): Your API key for authentication.authInstance
(SupabaseClient): An existing Supabase client instance for authentication.httpParams
(ApiConfig): Configuration for the HTTP client.httpInstance
(HttpClient): An existing HttpClient instance.clientId (string): Moon oauth2 client id param
Methods
connect(accessToken?: string, refreshToken?: string)
: Establishes a connection to the Moon API.disconnect()
: Disconnects from the Moon API.getMoonAuth()
: Returns the Supabase client instance for authentication.getUserSession()
: Returns the current user session.getSolanaSDK()
: Returns the Solana SDK instance.getBitcoinSDK()
: Returns the Bitcoin SDK instance.getCosmosSDK()
: Returns the Cosmos SDK instance.getEosSDK()
: Returns the EOS SDK instance.getLitecoinSDK()
: Returns the Litecoin SDK instance.getRippleSDK()
: Returns the Ripple SDK instance.getTronSDK()
: Returns the Tron SDK instance.getBitcoincashSDK()
: Returns the Bitcoincash SDK instance.getDogecoinSDK()
: Returns the Dogecoin SDK instance.getAccountsSDK()
: Returns the Accounts SDK instance.getAaveSDK()
: Returns the Aave SDK instance.getConveyorfinanceSDK()
: Returns the Conveyorfinance SDK instance.getENSSDK()
: Returns the ENS SDK instance.getErc20SDK()
: Returns the ERC-20 SDK instance.getErc1155SDK()
: Returns the ERC-1155 SDK instance.getErc721SDK()
: Returns the ERC-721 SDK instance.getOneinchSDK()
: Returns the 1inch SDK instance.getUniswapSDK()
: Returns the Uniswap SDK instance.getYearnSDK()
: Returns the Yearn SDK instance.listAccounts()
: Lists all available accounts.createAccount()
: Creates a new account.SignTransaction(wallet: string, transaction: InputBody)
: Signs a transaction.SignMessage(wallet: string, message: BytesLike)
: Signs a message.SignTypedData(wallet: string, domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, string>)
: Signs typed data.SendTransaction(wallet: string, rawTransaction: string, chain_id: string)
: Broadcasts a transaction.getChains()
: Retrieves a list of supported chains.getChainById(id: string)
: Retrieves a chain by its ID.
Authentication Methods
The Moon SDK supports various authentication methods to provide secure access to the blockchain functionalities. The following authentication methods are available:
Usage
Here's a basic example of how to use the SDK:
Discord OAuth
To authenticate using Discord OAuth, follow these steps:
Initiate the Discord OAuth flow:
After the user is redirected to the Discord authorization page, obtain the authorization code from the URL.
Exchange the authorization code for an access token and refresh token:
GitHub OAuth
To authenticate using GitHub OAuth, follow these steps:
Initiate the GitHub OAuth flow:
After the user is redirected to the GitHub authorization page, obtain the authorization code from the URL.
Exchange the authorization code for an access token and refresh token:
Google OAuth
To authenticate using Google OAuth, follow these steps:
Initiate the Google OAuth flow:
After the user is redirected to the Google authorization page, obtain the authorization code from the URL.
Exchange the authorization code for an access token and refresh token:
Twitter OAuth
To authenticate using Twitter OAuth, follow these steps:
Initiate the Twitter OAuth flow:
After the user is redirected to the Twitter authorization page, obtain the authorization code from the URL.
Exchange the authorization code for an access token and refresh token:
Magic Link
To authenticate using a magic link, follow these steps:
Send a magic link to the user's email address:
The user will receive an email with a magic link. After clicking the link, they will be redirected to the specified
redirectTo
URL.
Email and Password
To authenticate using email and password, follow these steps:
Create a new user account:
Sign in with the created account:
Phone and Password
To authenticate using phone and password, follow these steps:
Sign in with the phone number and password:
Passkey
To authenticate using a passkey, follow these steps:
Initiate the passkey login flow:
Use the
options
to authenticate the user using their passkey.Verify the passkey login credentials:
SIWE (Sign-In with Ethereum)
To authenticate using SIWE, follow these steps:
Retrieve a nonce for the Ethereum address:
Sign the SIWE message using the Ethereum wallet.
Verify the SIWE signature:
Embedded Account
To create an embedded account, follow these steps:
Create an embedded account for the specified email address, UUID, and domain:
Last updated