List Available Contracts
Before you can get a quote for a staking, you'll need to choose the contract you want to stake into. The Swing SDK provides a few utility methods to a list of all available contracts. You'll need the contract.id
to get a list of quotes and make a deposit.
import { SwingSDK } from '@swing.xyz/sdk';
const swingSDK = new SwingSDK({
// Your Swing Platform project identifier
projectId: 'swing-project-id',
});
// Initialize the SDK with configuration data
await swingSDK.init();
// All available contracts are available
const contracts = swingSDK.contracts;
// Get a single contract by ID
const contract: Contract[] = swingSDK.getContract({ id: 'contract-id' });
Contract Interface
Below you will find the interface returned by the Swing SDK when interacting with contracts.
interface Contract {
id: string; // Unique Swing Identifier
type: 'deposit' | 'withdraw';
address: string; // Deployed contract address
method: string; // Contract method (eg. deposit, withdraw)
chain: string;
inputToken: Token; // Token you send to the contract
outputToken: Token | null; // Token you receive from the contract
// Swing's integration provider
integration: {
type: 'staking';
slug: string;
name: string;
logo: string;
monetization: boolean;
};
}
Get available staking integrations
You can get list of integrations that support staking by filtering the integrations property
.
const stakingIntegrations = swingSDK.integrations.filter(
(integration) => integration.type === 'staking',
);
Get available contracts for an integration
If you already know what integration the user wants to use, you can quickly get a list of all contracts for that integration.
const integration = swingSDK.getIntegration('lido');
const contracts = swingSDK.contracts.filter(
(contract) => contract.integration.slug === integration.slug,
);
Get available deposit or withdraw contracts
You can get a list of all available deposit or withdraw contracts by calling the getContractsByType
method.
const depositContracts = swingSDK.getContractsByType('deposit');
const withdrawContracts = swingSDK.getContractsByType('withdraw');
Get available contracts for a chain
It might be useful to display a list of all available contracts for a chain. You can do this by providing the chainSlug
to the getContractsForChain
method.
const contracts = swingSDK.getContractsForChain({
chainSlug: 'ethereum',
// Optional: Filter by contract type
// type: 'deposit' | 'withdraw'
});
Get available contracts for a chain and token
If you already know what token the user wants to deposit, you can quickly get a list of all contracts for the matching chain and token.
const contracts = swingSDK.getContractsForChainToken({
chainSlug: 'ethereum',
tokenSymbol: 'ETH',
// Optional: Filter by contract type
// type: 'deposit' | 'withdraw'
});
Get available staking tokens
You can get a list of all available staking tokens by calling the getAvailableStakingTokens
method.
const stakingTokens = swingSDK.getAvailableStakingTokens({
// Optional: Filter by chain
// chainSlug: 'ethereum',
//
// Optional: Filter by contract type
// type: 'deposit' | 'withdraw'
});