Monero wallet and daemon JavaScript API. https://github.com/monero-ecosystem/monero-javascript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woodser 6480bb3363 re-enable tests 8 months ago
bin refactor project to use src folder 11 months ago
src Can get and set arbitrary key/value attributes 8 months ago
tests re-enable tests 8 months ago
.eslintignore first commit: initial project, monero core c++ to es5 with 11 months ago
.eslintrc.json first commit: initial project, monero core c++ to es5 with 11 months ago
.gitignore first commit: initial project, monero core c++ to es5 with 11 months ago
.gitmodules rename to mymonero-core-js 11 months ago
.project first commit: initial project, monero core c++ to es5 with 11 months ago
LICENSE.txt first commit: initial project, monero core c++ to es5 with 11 months ago
README.md update sample code 8 months ago
donate.png add donation address 9 months ago
package-lock.json added promise-throttle dependency and instrumented rpc 10 months ago
package.json longer test timeout 9 months ago
todo.txt implement tx pool stats up until binary conversion of 'histo' 8 months ago
webpack.browser.dev.config.js first commit: initial project, monero core c++ to es5 with 11 months ago
webpack.browser.prod.config.js first commit: initial project, monero core c++ to es5 with 11 months ago
webpack.config.browser.common.js refactor project to use src folder 11 months ago

README.md

Monero JavaScript API

Introduction

This project provides a modern JavaScript API for a Monero wallet and daemon.

The API currently relies on running instances of Monero Wallet RPC and Monero Daemon RPC. Primary goals of this project are to support a local wallet with client-side crypto and a MyMonero wallet which shares the view key with a 3rd party to scan the blockchain.

Main Features

  • General-purpose library with focus on ease-of-use
  • Clear object-oriented models to formalize Monero types and their relationships to each other
  • Powerful API to query transactions, transfers, and vouts by their attributes
  • Extensive test suite (110+ passing tests)
  • Fetch and process binary data from the daemon in JavaScript using client-side crypto

Wallet Sample Code

See the tests for the most complete examples of using this library.

// create a wallet that uses a monero-wallet-rpc endpoint
let wallet = new MoneroWalletRpc({
  uri: "http://localhost:38083",
  user: "rpc_user",
  pass: "abc123"
});

// get wallet balance as BigInteger
// e.g. 533648366742
let balance = await wallet.getBalance();
   
// get wallet primary address
// e.g. 59aZULsUF3YNSKGiHz4JPMfjGYkm1S4TB3sPsTr3j85HhXb9crZqGa7jJ8cA87U48kT5wzi2VzGZnN2PKojEwoyaHqtpeZh
let primaryAddress = await wallet.getPrimaryAddress();
    
// get address and balance of subaddress [1, 0]
let subaddress = await wallet.getSubaddress(1, 0);
let subaddressBalance = subaddress.getBalance();
let subaddressAddress = subaddress.getAddress();

// send to an address
let sentTx = await wallet.send("74oAtjgE2dfD1bJBo4DWW3E6qXCAwUDMgNqUurnX9b2xUvDTwMwExiXDkZskg7Vct37tRGjzHRqL4gH4H3oag3YyMYJzrNp", new BigInteger(50000));

// send to multiple addresses from subaddress 0, 1 which can be split into multiple transactions
let sendConfig = new MoneroSendConfig();
sendConfig.setDestinations([
  new MoneroDestination("7BV7iyk9T6kfs7cPfmn7vPZPyWRid7WEwecBkkVr8fpw9MmUgXTPtvMKXuuzqKyr2BegWMhEcGGEt5vNkmJEtgnRFUAvf29", new BigInteger(50000)),
  new MoneroDestination("78NWrWGgyZeYgckJhuxmtDMqo8Kzq5r9j1kV8BQXGq5CDnECz2KjQeBDc3KKvdMQmR6TWtfbRaedgbSGmmwr1g8N1rBMdvW", new BigInteger(50000))
]);
sendConfig.setAccountIndex(0);
sendConfig.setSubaddressIndices([1]);
let sentTxs = await wallet.sendSplit(sendConfig);

// get confirmed transactions
for (let tx of await wallet.getTxs({isConfirmed: true})) {
  let txId = tx.getId();                 // e.g. f8b2f0baa80bf6b686ce32f99ff7bb15a0f198baf7aed478e933ee9a73c69f80
  let txFee = tx.getFee();               // e.g. 750000
  let isConfirmed = tx.getIsConfirmed(); // e.g. true
}

// get incoming transfers to account 0
for (let transfer of await wallet.getTransfers({isIncoming: true, accountIndex: 0})) {
  let amount = transfer.getAmount();     // e.g. 752343011023
}

Daemon Sample Code

// create a daemon that uses a monero-daemon-rpc endpoint
let daemon = new MoneroDaemonRpc({uri: "http://localhost:38081"});

// get daemon info
let height = await daemon.getHeight();           // e.g. 1523651
let feeEstimate = await daemon.getFeeEstimate(); // e.g. 750000

// get first 100 blocks as a binary request
let blocks = await daemon.getBlocksByRange(0, 100);

// get block info
for (let block of blocks) {
  let blockHeight = block.getHeader().getHeight();
  let blockId = block.getHeader().getId();
  let blockSize = block.getHeader().getSize();
  let txCount = block.getTxs().length;
}

Running Tests

  1. Set up running instances of Monero Wallet RPC and Monero Daemon RPC. See Monero RPC Setup.
  2. git clone --recurse-submodules https://github.com/woodser/monero-javascript.git
  3. npm install
  4. Configure the appropriate RPC endpoints and authentication by modifying WALLET_RPC_CONFIG and DAEMON_RPC_CONFIG in TestUtils.js.
  5. npm test

Note: some tests are failing as not all functionality is implemented.

Monero RPC Setup

  1. Download and extract the latest Monero CLI for your platform.
  2. Start Monero daemon locally: ./monerod --stagenet (or use a remote daemon).
  3. Create a wallet file if one does not exist. This is only necessary one time.
    • Create new / open existing: ./monero-wallet-cli --daemon-address http://localhost:38081 --stagenet
    • Restore from mnemonic seed: ./monero-wallet-cli --daemon-address http://localhost:38081 --stagenet --restore-deterministic-wallet
  4. Start monero-wallet-rpc (requires --wallet-dir to run tests):

    e.g. For wallet name test_wallet_1, user rpc_user, password abc123, stagenet: ./monero-wallet-rpc --daemon-address http://localhost:38081 --stagenet --rpc-bind-port 38083 --rpc-login rpc_user:abc123 --wallet-dir /Applications/monero-v0.13.0.2

Interfaces and Types

Project Goals

  • Offer consistent terminology and APIs for Monero’s developer ecosystem
  • Build a wallet adapter for a local wallet which uses client-side crypto and a daemon
  • Build a wallet adapter for a MyMonero wallet which shares the view key with a 3rd party to scan the blockchain

License

This project is licensed under MIT.

46FR1GKVqFNQnDiFkH7AuzbUBrGQwz2VdaXTDD4jcjRE8YkkoTYTmZ2Vohsz9gLSqkj5EM6ai9Q7sBoX4FPPYJdGKQQXPVz

Thank you supporting this project.