Stake
Call
Arguments:
value
: string | bigint - amount of ETH to stake (in wei)callback
: StageCallback - callback function that will be on each stage of the transactionreferralAddress
: string - referral address (optional)
Callback stages:
sign
- waiting for the user to sign the transactionreceipt
= waiting for the transaction to be included in the blockconfirmation
- transaction is confirmed by the networkdone
- transaction is successfulmultisig_done
- transaction with multisig is successfulerror
- transaction is failed
import {
LidoSDK,
LidoSDKCore,
StakeStageCallback,
TransactionCallbackStage,
SDKError,
} from '@lidofinance/lido-ethereum-sdk';
const lidoSDK = new LidoSDK({
rpcUrls: ['https://rpc-url'],
chainId: 5,
web3Provider: LidoSDKCore.createWeb3Provider(5, window.ethereum),
});
const callback: StakeStageCallback = ({ stage, payload }) => {
switch (stage) {
case TransactionCallbackStage.SIGN:
console.log('wait for sign');
break;
case TransactionCallbackStage.RECEIPT:
console.log('wait for receipt');
console.log(payload, 'transaction hash');
break;
case TransactionCallbackStage.CONFIRMATION:
console.log('wait for confirmation');
console.log(payload, 'transaction receipt');
break;
case TransactionCallbackStage.DONE:
console.log('done');
console.log(payload, 'transaction confirmations');
break;
case TransactionCallbackStage.ERROR:
console.log('error');
console.log(payload, 'error object with code and message');
break;
default:
}
};
try {
const stakeTx = await lidoSDK.stake.stakeEth({
value,
callback,
referralAddress,
account,
});
console.log(
stakeTx,
'transaction hash, transaction receipt, confirmations, stake result',
stakeTx.result.stethReceived,
stakeTx.result.sharesReceived,
);
} catch (error) {
console.log((error as SDKError).errorMessage, (error as SDKError).code);
}