unstakeHbar
How to call the API from an app
Hedera Wallet Snap connects to your currently connected Metamask account by default. To learn how apps can connect to Hedera Wallet Snap using a non-metamask(external) account, refer to this documentation.
Then, depending on whether you're trying to connect to a metamask account or a non-metamask account, you can call the snap API in the following way:
const snapId = `npm:@hashgraph/hedera-wallet-snap`
const unstakeHbarAPI = async () => {
const externalAccountParams = {
externalAccount: {
accountIdOrEvmAddress: '0.0.12345',
curve: 'ED25519'
}
}
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId,
request: {
method: 'unstakeHbar',
params: {
network: 'testnet',
nodeId: 0
/*
Uncomment the below line if you want to connect
to a non-metamask account
*/
// ...externalAccountParams
}
}
}
})
}What the API does
Retrieves the currently connected account the user has selected on Metamask. If it's the first time, a new snap account is created and the account info is saved in snap state.
Calls the Hedera SDK Update Account API to change the property related to staking which means it will also update
setDeclineStakingRewardto true hence, the account will stop receiving staking rewardsReturns the transaction receipt as response
Some example responses:
For a hedera account id 0.0.4559:
Unstake Hbar Live Demo on CodePen
Last updated
Was this helpful?

