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