Skip to content

Commit

Permalink
feat: update sendCalls to match EIP-5792 spec (#2641)
Browse files Browse the repository at this point in the history
* feat: up 5792

* chore: changeseT
  • Loading branch information
jxom authored Aug 22, 2024
1 parent 9a1c6ab commit 89d11ed
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 492 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-boats-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Experimental:** Deprecated `writeContracts`. Use `sendCalls` instead.
5 changes: 5 additions & 0 deletions .changeset/nice-trainers-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Experimental:** Updated `sendCalls` to match the updated EIP-5792 spec (`chainId` per call).
5 changes: 5 additions & 0 deletions .changeset/violet-schools-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**Experimental:** Updated `sendCalls` to also accept contract function interface.
23 changes: 15 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions site/pages/experimental/eip5792/sendCalls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,82 @@ export const walletClient = createWalletClient({

:::

### Contract Calls

The `calls` property also accepts **Contract Calls**, and can be used via the `abi`, `functionName`, and `args` properties.

:::code-group

```ts twoslash [example.ts]
import { parseAbi } from 'viem'
import { walletClient } from './config'

const abi = parseAbi([
'function approve(address, uint256) returns (bool)',
'function transferFrom(address, address, uint256) returns (bool)',
])

const id = await walletClient.sendCalls({ // [!code focus:99]
calls: [
{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
},
{
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi,
functionName: 'approve',
args: [
'0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
100n
],
},
{
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi,
functionName: 'transferFrom',
args: [
'0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
'0x0000000000000000000000000000000000000000',
100n
],
},
],
})
```

```ts twoslash [abi.ts] filename="abi.ts"
export const wagmiAbi = [
// ...
{
inputs: [],
name: "mint",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
// ...
] as const;
```

```ts [config.ts] filename="config.ts"
import 'viem/window'
import { createWalletClient, custom } from 'viem'
import { walletActionsEip5792 } from 'viem/experimental'

// Retrieve Account from an EIP-1193 Provider.
const [account] = await window.ethereum!.request({
method: 'eth_requestAccounts'
})

export const walletClient = createWalletClient({
account,
transport: custom(window.ethereum!)
}).extend(walletActionsEip5792())
```

:::

## Returns

`string`
Expand Down
Loading

0 comments on commit 89d11ed

Please sign in to comment.