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' });
CopyCopied!
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 ;
};
}
CopyCopied!
You can get list of integrations that support staking by filtering the integrations property
.
const stakingIntegrations = swingSDK.integrations. filter (
( integration ) => integration.type === 'staking' ,
);
CopyCopied!
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,
);
CopyCopied!
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' );
CopyCopied!
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'
});
CopyCopied!
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'
});
CopyCopied!
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'
});
CopyCopied!