Skip to content

Commit

Permalink
docs: add simulate example to write (#3762)
Browse files Browse the repository at this point in the history
* update docs

* docs: up

---------

Co-authored-by: wslyvh <wslyvh@users.noreply.github.com>
  • Loading branch information
tmm and wslyvh authored Mar 27, 2024
1 parent d6bc98c commit dbd6446
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/core/api/actions/writeContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ const result = await writeContract(config, {
<<< @/snippets/core/config.ts[config.ts]
:::

::::tip Pairing with `simulateContract`

Pairing [`simulateContract`](/core/api/actions/simulateContract) with `writeContract` allows you to validate if the transaction will succeed ahead of time. If the simulate succeeds, `writeContract` can execute the transaction.

::: code-group
```ts [index.ts]
import { simulateContract, writeContract } from '@wagmi/core'
import { abi } from './abi'
import { config } from './config'

const { request } = await simulateContract(config, {
abi,
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
functionName: 'transferFrom',
args: [
'0xd2135CfB216b74109775236E36d4b433F1DF507B',
'0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
123n,
],
})
const hash = await writeContract(config, request)
```
<<< @/snippets/abi-write.ts[abi.ts]
<<< @/snippets/core/config.ts[config.ts]
:::
::::


## Parameters

```ts
Expand Down

0 comments on commit dbd6446

Please sign in to comment.