description |
---|
You can easily use Blocto on Wagmi |
Wagmi is a collection of React Hooks containing everything you need to start working with Ethereum. Wagmi makes it easy to "Connect Wallet," display ENS and balance information, sign messages, interact with contracts, and much more — all with caching, request deduplication, and persistence.
Blocto currently supported various wallet connect solutions based on Wagmi,
these solutions provide an amazing user experience. before you begin reading, you can take a look at the links above.
Install from npm/yarn/pnpm
{% tabs %} {% tab title="npm" %}
npm i @blocto/wagmi-connector@^1.3.1 wagmi@^1.4.12 viem@~1.0.0
{% endtab %}
{% tab title="yarn" %}
yarn add @blocto/wagmi-connector@^1.3.1 wagmi@^1.4.12 viem@~1.0.0
{% endtab %}
{% tab title="pnpm" %}
pnpm add @blocto/wagmi-connector@^1.3.1 wagmi@^1.4.12 viem@~1.0.0
{% endtab %} {% endtabs %}
import { configureChains, mainnet } from 'wagmi'
import { mainnet, arbitrum, optimism, polygon, bsc, avalanche } from 'wagmi/chains'
import { bscTestnet, sepolia } from 'wagmi/chains'
import { publicProvider } from 'wagmi/providers/public'
// Mainnet
const BLOCTO_SUPPORTED_MAINNET_CHAIN = [mainnet, arbitrum, optimism, polygon, bsc, avalanche];
// Testnet
const BLOCTO_SUPPORTED_TESTNET_CHAIN = [bscTestnet, sepolia];
const { chains, publicClient, webSocketPublicClient } = configureChains(
BLOCTO_SUPPORTED_TESTNET_CHAIN,
[publicProvider()],
)
Using publicProvider
in a production environment is not recommended. It's advisable to use alchemyProvider
or infuraProvider
as alternatives for the production environment's provider.
Mainnet | Testnet |
---|---|
Ethereum | Sepolia |
Arbitrum | ArbitrumSepolia |
Optimism | OptimismSepolia |
Polygon | X |
Binance | BinanceTestnet |
Avalanche | AvalancheFuji |
Base | BaseSepolia |
Zora | ZoraTestnet |
Scroll | ScrollSepolia |
import { BloctoConnector } from '@blocto/wagmi-connector'
const config = createConfig({
autoConnect: true,
connectors: [new BloctoConnector({ chains, options: { appId: 'REPLACE_WITH_YOUR_DAPP_ID' } })]
publicClient,
webSocketPublicClient,
})
Paramter | Type | Description | Required |
---|---|---|---|
chains | Chain[] | Connector supports Chains | YES |
options.appId | String | Blocto dApp ID | NO |
function App() {
return (
<WagmiConfig config={config}>
<YourRoutes />
</WagmiConfig>
)
}
import { useAccount, useConnect, useEnsName } from 'wagmi'
function Profile() {
const { address, isConnected } = useAccount()
const { data: ensName } = useEnsName({ address })
const { connect, connectors } = useConnect()
const [blocto] = connectors
if (isConnected) return <div>Connected to {ensName ?? address}</div>
return <button onClick={() => connect({ connector: blocto })}>Connect Wallet</button>
}
{% embed url="https://codesandbox.io/s/github/blocto/blocto-sdk-examples/tree/main/src/adapter/evm/with-wagmi-v1?file=/src/wagmi.ts" %}