2.8 KiB
2.8 KiB
title, description
| title | description |
|---|---|
| useSendCalls | Hook that requests for the wallet to sign and broadcast a batch of calls (transactions) to the network. |
useSendCalls
Hook that requests for the wallet to sign and broadcast a batch of calls (transactions) to the network.
Import
import { useSendCalls } from 'wagmi'
Usage
::: code-group
import { useSendCalls } from 'wagmi'
import { parseEther } from 'viem'
function App() {
const sendCalls = useSendCalls()
return (
<button
onClick={() =>
sendCalls.mutate({
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
},
{
data: '0xdeadbeef',
to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
},
]
})
}
>
Send calls
</button>
)
}
<<< @/snippets/react/config.ts[config.ts] :::
Synchronous Usage
If you want to wait for the calls to be included in a block, you can use useSendCallsSync:
::: code-group
import { useSendCallsSync } from 'wagmi'
import { parseEther } from 'viem'
function App() {
const sendCallsSync = useSendCallsSync()
return (
<button
onClick={() =>
sendCallsSync.mutate({
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
},
{
data: '0xdeadbeef',
to: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
},
]
})
}
>
Send calls
</button>
)
}
<<< @/snippets/react/config.ts[config.ts] :::
Parameters
import { type UseSendCallsParameters } from 'wagmi'
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
::: code-group
import { useSendCalls } from 'wagmi'
import { config } from './config' // [!code focus]
function App() {
const sendCalls = useSendCalls({
config, // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Return Type
import { type UseSendCallsReturnType } from 'wagmi'