Examples¶
Every library has the same data model and API, so the examples read the same in every language: pick a language in any tab and all the pages follow. They run against a stagenet node and a monero-wallet-rpc server on your machine.
Warning
Wallets handle real funds. Develop against regtest, stagenet or testnet, and never log or commit a seed or a private key.
What is in the examples¶
- RPC connection: make a connection, check it, connect a wallet to a daemon, and go through Tor.
- Daemon: the calls of the node, by category: blockchain, status, transactions and the pool, outputs and key images, peers and network, mining and managing the node.
- Wallets: the wallet implementations and how to use each one: wallet RPC, full wallet, keys wallet, accounts and addresses, sync and balances, files and attributes, view-only and offline and multisig.
- Transactions: send funds, outputs and sweeping, find transactions, and notes and proofs.
- Notifications: be called on the progress of a sync, on funds received or spent, on balances, and on new blocks.
- Utilities: convert amounts, check addresses and seeds, make integrated addresses and payment requests, and set the log.
- Serialization: turn the models into JSON and back.
- Errors: catch errors, read the code of an RPC error, and check before you call.
Get a library¶
| Language | How to get it |
|---|---|
| Python | Prebuilt .deb and wheel packages in the releases |
| Java | Gradle or Maven, or build it from source |
| Kotlin | Build it from source and publish it with ./gradlew publishToMavenLocal, it is not in a repository yet |
| C# | Monero.NET and Monero.Native, build them from source, they are not on nuget.org yet |
| C++ | Build it from source with CMake |
| C | Build it from source, as a shared or a static library |
Run a node and a wallet server¶
The RPC clients need a monerod and a monero-wallet-rpc to talk to. docker-monero-rpc has a compose file that starts both on stagenet:
git clone https://github.com/libmonero/docker-monero-rpc
cd docker-monero-rpc
docker compose -f examples/docker-compose.yml up -d
| Server | URL | Login |
|---|---|---|
monerod |
http://localhost:38081 |
superuser / abctesting123 |
monero-wallet-rpc |
http://localhost:38083 |
rpc_user / abc123 |
The node has to download the stagenet chain the first time, which takes a while. To try the code without waiting, use the regtest compose file, and take the ports and the logins from it.
A native wallet, the ones with Full and Keys in the name, runs in your process and needs no wallet server. A full wallet connects to the daemon, and a keys wallet needs nothing.
Handle errors¶
A call that fails throws an error, in every language but C, where it returns MONERO_ERROR. The examples leave the checks out, to stay short. See Errors for how to catch them, read the code of an RPC error, and check before you call.
Go further¶
- Libraries has the repository of every language, with its own sample code, build instructions and tests.
- The data model and API specification shows every type and function with diagrams, and applies to every language.
- The monero-python API reference documents the wallet and daemon interfaces, and its names translate to the other languages.