Skip to main content
This guide walks you through creating a wallet, signing a message, and sending your first transaction using the MoonKey REST API.

Prerequisites

Before you begin, make sure you have:
  • Completed the REST API setup guide
  • Your MoonKey API key (test or live)
  • A test user ID (or follow step 0 to create one)
All examples in this guide use test API keys. Replace sk_test_your_api_key_here with your actual API key.

Create a User (Optional)

If you want your wallet to be owned by a specific user, first create a user account:
The response will include the user ID:
Save the id field from the response. You’ll need it in the next step to create a wallet for this user.

1. Create a Wallet

Let’s create an Ethereum wallet for your user:
The response will include the wallet ID and public address:
If a wallet of the same type already exists for the user, MoonKey will return the existing wallet instead of creating a new one.
Save the wallet id and public_address. You’ll need these for the next steps.

2. Sign a Message

Now let’s sign a message with your newly created wallet:
The response will contain the signed message:

3. Send a Transaction

Finally, let’s send a transaction on Ethereum’s testnet, Sepolia:
You’ll need to fund your wallet with Sepolia ETH for this step. Use a Sepolia faucet to send test ETH to your wallet’s public_address.
The response will contain the signature and signed transaction:

Broadcasting the Transaction

The signed_transaction is ready to be broadcast to the Ethereum network. You can use it with the eth_sendRawTransaction RPC method:
View your transaction on Sepolia Etherscan by searching for the transaction hash.

Understanding Transaction Parameters

When sending a transaction, you need to provide several parameters:
Use tools like eth-converter.com to convert between decimal and hex values for ETH amounts and gas prices.

Creating Solana Wallets

MoonKey also supports Solana wallets. To create a Solana wallet, simply change the wallet_type:

Best Practices

Security

  • Never expose API keys - Keep your secret API keys secure on your backend
  • Use test keys for development - Test thoroughly before switching to live keys
  • Validate user actions - Always verify that requests come from authenticated users

Transaction Safety

  • Verify addresses - Always double-check recipient addresses before sending transactions
  • Test on testnet first - Use Sepolia for Ethereum or Devnet for Solana before going to mainnet
  • Monitor transaction status - Track transactions and handle failures gracefully
  • Use appropriate gas limits - Ensure transactions have enough gas to complete

Error Handling

Always implement proper error handling for API requests:

Troubleshooting

Common Issues

401 Unauthorized
  • Verify your API key is correct
  • Ensure you’re using the Bearer token format
  • Check that your API key hasn’t been revoked
404 Not Found
  • Verify the wallet ID is correct
  • Ensure the wallet belongs to your app
  • Check that the user ID exists
Transaction Fails
  • Verify the wallet has sufficient balance
  • Check that gas limits and fees are appropriate
  • Ensure the recipient address is valid
  • Verify you’re on the correct network (testnet vs mainnet)
Rate Limiting
  • Implement exponential backoff for retries
  • Cache wallet data when possible
  • Batch operations where appropriate

Support

Need help?