Overview
Some of our packages contain functions that require a provider or signer to be passed in. This section will highlight how you may implement the retrieval of a provider or signer in your frontend.
Wagmi Quickstart
Setup
In order to obtain a provider/signer we must first initialize the sdk, setup a client, and connect a wallet to our application. Learn more about our wagmi functions in our Wagmi Overview Section
// initialize the sdk
const wagmi = await initializeWagmi(uniblock_api_key);
// setup a client
const { chains, provider, webSocketProvider } = wagmi.configureChains([5]);
const client = wagmi.createClient(
provider,
webSocketProvider,
chains,
[
connector.INJECTED_CONNECTOR,
],
);
// connect wallet
await wagmi.connectWallet(client, connector.INJECTED_CONNECTOR);
Provider
We can now call the getProvider
method.
const provider = await wagmi.getProvider();
Signer
We can now call the getSigner
method.
const signer = await wagmi.getSigner();
Examples
Below are some examples of how you can use the functions above to make calls to functions in our various packages that require a user's provider or signer.
Uniswap
const uniswap = await initializeUniswap(uniblockApiKey);
const provider = await wagmi.getProvider(); // use our function to get provider
const signer = await wagmi.getSigner(); // use our function to get signer
const res = await (
await uniswap
).trade(
tradePoolAddress,
provider,
signer,
tradeChainId,
tradeAmount,
tradeWalletAddress,
tradeTokenInAddress,
tradeSlippageInPercentage,
tradeDeadlineInMin,
);
Launcher Airdrop
const airdropSdk = await initializeMultiSend(uniblockApiKey, {contractAddress, chainId});
const signer = await wagmi.getSigner(); // use our function to get signer
const res = await airdropSdk.claim(to, id, amount, proof, signer);
1inch
const oneInch = initializeOneInch(uniblockApiKey);
const signer = await wagmi.getSigner(); // use our function to get signer
const availability = await oneInch.checkAvailability(chainId);
// check if 1inch server is down or not
if(availability){
const result = await oneInch.swap(chainId, fromTokenAddress, toTokenAddress, amount, fromAddress, slippage, signer);
}