Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@harmony-js/staking
Advanced tools
This package provides a collection of apis to create, sign/send staking transaction, and receive confirm/receipt.
npm install @harmony-js/staking
Create a Harmony instance connecting to testnet
const { Harmony } = require('@harmony-js/core');
const {
ChainID,
ChainType,
hexToNumber,
numberToHex,
fromWei,
Units,
Unit,
} = require('@harmony-js/utils');
const hmy = new Harmony(
'https://api.s0.b.hmny.io/',
{
chainType: ChainType.Harmony,
chainId: ChainID.HmyTestnet,
},
);
Below, examples show how to send delegate, undelegate, and collect rewards staking transactions. First, set the chainId, gasLimit, gasPrice for all subsequent staking transactions
hmy.stakings.setTxParams({
gasLimit: 25000,
gasPrice: numberToHex(new hmy.utils.Unit('1').asGwei().toWei()),
chainId: 2
});
Note: create and edit validator transactions are not fully supported in the sdk
Create delegate staking transaction
const delegate = hmy.stakings.delegate({
delegatorAddress: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7',
validatorAddress: 'one1vfqqagdzz352mtvdl69v0hw953hm993n6v26yl',
amount: numberToHex(new Unit(1000).asOne().toWei())
});
const delegateStakingTx = delegate.build();
Sign and send the delegate transaction and receive confirmation
// key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
hmy.wallet.signStaking(delegateStakingTx).then(signedTxn => {
signedTxn.sendTransaction().then(([tx, hash]) => {
console.log(hash);
signedTxn.confirm(hash).then(response => {
console.log(response.receipt);
});
});
});
Similarily, undelegate and collect reward transactions can be composed, signed and sent Create undelegate staking transaction
const undelegate = hmy.stakings.undelegate({
delegatorAddress: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7',
validatorAddress: 'one1vfqqagdzz352mtvdl69v0hw953hm993n6v26yl',
amount: numberToHex(new Unit(1000).asOne().toWei())
});
const undelegateStakingTx = undelegate.build();
Create collect rewards staking transaction
const collectRewards = hmy.stakings.collectRewards({
delegatorAddress: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7'
});
const collectRewardsStakingTx = collectRewards.build();
Also, similar to normal transaction, signing and sending can be performed asynchronously.
FAQs
staking transaction package for harmony
The npm package @harmony-js/staking receives a total of 320 weekly downloads. As such, @harmony-js/staking popularity was classified as not popular.
We found that @harmony-js/staking demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.