Skip to content

crossfidev/js-rpcapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

const { mpapi } = require('mpapi');

// Connect to

mpapi.node.setProvider("http://127.0.0.1:8732");
mpapi.node.setDebugMode(true);
  1. Create new account
// Generate seed phrase
const mnemonic = mpapi.crypto.generateMnemonic();
// Generate new keys of account
const keys = mpapi.crypto.generateKeys(mnemonic);
  1. Get existing account by private key
const extractedKeys = mpapi.crypto.extractKeys('edsk3uku2wuuMztoazUmusXoRgFYRJyPyN9QYdoPDZo6JEKM3QMd5t');
  1. Get plex_balance
const plex_balance = utility.totez(await mpapi.rpc.getPlexBalance(extractedKeys.pkh));)
  1. Get mine_balance
const mine_balance = utility.totez(await mpapi.rpc.getMineBalance(extractedKeys.pkh));
  1. Send mine to another account
const operations = await mpapi.rpc.mine_transfer(
  extractedKeys.pkh, 
  extractedKeys, 
  'mp1MN1YB8ofoZokHyUAmH9oYKfxEHqF1XkT7', // Receiver
  100, // Amount of mine
  1 // Default fee
);
  1. Send plex to another account
const operations = await mpapi.rpc.plex_transfer(
  extractedKeys.pkh, 
  extractedKeys, 
  'mp1MN1YB8ofoZokHyUAmH9oYKfxEHqF1XkT7', // Receiver
  100, // Amount of plex
  1 // Default fee (mine value)
);
  1. Set delegate
const operations = await mpapi.rpc.setDelegate(
  extractedKeys.pkh, 
  extractedKeys, 
  'mp1FCcGeqnRG2wawPaerF7JbY8EQ8dvm8wig', // Delegate address
  1 // Default fee
);
  1. Undelegate
const operations = await mpapi.rpc.setDelegate(
  extractedKeys.pkh, 
  extractedKeys, 
  undefined, 
  1 // Default fee
);
  1. Looging for operation in blocks
const blockHash = await mpapi.rpc.findOperation(
  'oo7D7FnyLeDL9VCNiXWY9cty8MvTzX8HDSGmuqGDfSNSwnwLogm',
  50 // Count blocks ago);
  1. Looging for operation in blocks
const blockHash = await mpapi.rpc.awaitOperation(
  'oo7D7FnyLeDL9VCNiXWY9cty8MvTzX8HDSGmuqGDfSNSwnwLogm');
  1. Example of catching errors
try {
  const blockHash = await mpapi.rpc.findOperation(
    'oo7D7FnyLeDL9VCNiXWY9cty8MvTzX8HDSGmuqGDfSNSwnwLogm',
    2
  );
} catch (error) {
  console.log(error)
}

About

JS RPC API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published