@wagmi/core
Version:
VanillaJS library for Ethereum
121 lines • 3.21 kB
JavaScript
import { Actions } from 'viem/tempo';
import { getConnectorClient, } from '../../actions/getConnectorClient.js';
/**
* Transfers a TIP-20 token. By default, submits the transfer without
* showing an editable UI. Pass `editable: true` to open the wallet's
* send UI with optional pre-filled fields.
*
* @example
* ```ts
* import { createConfig, http } from '@wagmi/core'
* import { tempo } from '@wagmi/core/chains'
* import { Actions } from '@wagmi/core/tempo'
*
* const config = createConfig({
* chains: [tempo],
* transports: {
* [tempo.id]: http(),
* },
* })
*
* const { receipt } = await Actions.wallet.transfer(config, {
* amount: '1.5',
* to: '0x...',
* token: 'pathUSD',
* })
*
* // Open the wallet UI instead.
* await Actions.wallet.transfer(config, {
* editable: true,
* token: 'pathUSD',
* })
* ```
*
* @param config - Config.
* @param parameters - Parameters.
* @returns The submitted transfer receipt and chain ID.
*/
export async function transfer(config, parameters) {
const { account, chainId, connector, ...rest } = parameters;
const client = await getConnectorClient(config, {
account,
assertChainId: false,
chainId,
connector,
});
return Actions.wallet.transfer(client, rest);
}
/**
* Opens the wallet swap flow with optional pre-filled swap fields.
*
* @example
* ```ts
* import { createConfig, http } from '@wagmi/core'
* import { tempo } from '@wagmi/core/chains'
* import { Actions } from '@wagmi/core/tempo'
*
* const config = createConfig({
* chains: [tempo],
* transports: {
* [tempo.id]: http(),
* },
* })
*
* const { receipt } = await Actions.wallet.swap(config, {
* amount: '1.5',
* token: '0x...',
* type: 'sell',
* })
* ```
*
* @param config - Config.
* @param parameters - Parameters.
* @returns The submitted swap receipt.
*/
export async function swap(config, parameters = {}) {
const { account, chainId, connector, ...rest } = parameters;
const client = await getConnectorClient(config, {
account,
assertChainId: false,
chainId,
connector,
});
return Actions.wallet.swap(client, rest);
}
/**
* Opens the wallet deposit flow with optional pre-filled deposit fields.
*
* @example
* ```ts
* import { createConfig, http } from '@wagmi/core'
* import { mainnet } from '@wagmi/core/chains'
* import { Actions } from '@wagmi/core/tempo'
*
* const config = createConfig({
* chains: [mainnet],
* transports: {
* [mainnet.id]: http(),
* },
* })
*
* const result = await Actions.wallet.deposit(config, {
* token: '0x...',
* value: '1.5',
* })
* ```
*
* @param config - Config.
* @param parameters - Parameters.
* @returns Receipts for onchain deposit operations, when applicable.
*/
export async function deposit(config, parameters = {}) {
const { account, chainId, connector, ...rest } = parameters;
const client = await getConnectorClient(config, {
account,
assertChainId: false,
chainId,
connector,
});
return Actions.wallet.deposit(client, { ...rest, chainId });
}
//# sourceMappingURL=wallet.js.map