Getting Started
Important Notice
This integration toolkit is currently in a demonstration phase. The methods and processes outlined in this document are for illustrative purposes only and may be subject to change. Please note that this toolkit is not yet live, and the final implementation may differ from the examples provided here.
To start using swBTC using the SDK toolkit:
- Import the SDK module for staking and checking data.
- Start a new module instance to enable the smart contract interactions.
- Use the SDK stake module to deposit WBTC and receive swBTC
- Use the SDK data module to check the total rewards accrued over time
- Use the SDK stake module to withdraw WBTC by returning swBTC
Request examples are provided below.
1. Import
import { SDKStake, SDKData } from '@p2p.org/swell-sdk';
2. Initialization
// set your RPC endpoint
const rpc = "<Your_RPC_Endpoint>";
// initiate SDK stake module
const stakeSDK = new SDKStake({
rpcProvider: rpc, // optional
});
// initiate SDK data module
const dataSDK = new SDKData({
rpcProvider: rpc, // optional
});
3. Deposit WBTC to receive swBTC
To deposit WBTC and receive swBTC, use the following code:
const provider = new providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const fromAddress = await signer.getAddress();
const depositTX = await stakeSDK.deposit(amount, fromAddress);
// return the transaction hash
const txHash = depositTX.result;
console.log("Transaction Hash:", txHash);
4. Check Total Rewards Accrued Over Time
You can check the total rewards accrued by your swBTC holdings over a specific time period:
const totalRewards = await dataSDK.getTotalRewards(fromAddress.address, timePeriod);
console.log("Total Rewards Accrued:", totalRewards);
5. Withdraw WBTC
To withdraw WBTC along with any accrued rewards by returning swBTC, follow this process:
const withdrawTX = await stakeSDK.withdraw(amount, fromAddress);
// return the transaction hash
const txHash = withdrawTX.result;
console.log("Withdrawal Transaction Hash:", txHash);
By following these steps, you should be able to effectively manage swBTC transactions and monitor your rewards using the SDK.
If you encounter any issues or need further clarification, please contact us.
Updated 4 months ago