@moonup/moon-api
@moonup/moon-api Package Documentation
Installing Moon API:
To install Moon API:
npm install @moonup/moon-apiyarn add @moonup/moon-apipnpm add @moonup/moon-apiUsage
import { HttpClient, Accounts } from '@moonup/moon-api';
// Initialize the HttpClient with your API base URL and security worker
const http = new HttpClient({
baseUrl: 'https://beta.usemoon.ai',
securityWorker: async (securityData) => {
return {
headers: {
Authorization: `Bearer ${securityData.token}`,
},
};
},
});
// Create an instance of the Accounts class
const accounts = new Accounts(http);
// Create a new Ethereum account
const createAccountData = await accounts.createAccount({ private_key: 'your_private_key' });
console.log('New account created:', createAccountData.address);
// Transfer ETH from the new account to another account
const transferEthData = await accounts.transferEth(createAccountData.name, {
to: '0xAnotherAccountAddress',
value: '1000000000000000000', // 1 ETH in wei
});
console.log('Transfer successful:', transferEthData.transactionHash);Initialization
Classes
Last updated