-
-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
421 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"viem": patch | ||
--- | ||
|
||
Added `decodeDeployData`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,112 @@ | ||
# decodeConstructorData | ||
# decodeDeployData | ||
|
||
TODO | ||
Decodes ABI encoded deploy data (bytecode & arguments). | ||
|
||
The opposite of [`encodeDeployData`](/docs/contract/encodeDeployData). | ||
|
||
## Install | ||
|
||
```ts | ||
import { decodeDeployData } from 'viem' | ||
``` | ||
|
||
## Usage | ||
|
||
::: code-group | ||
|
||
```ts [example.ts] | ||
import { decodeFunctionData } from 'viem' | ||
|
||
const { args } = decodeFunctionData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c63430008070033', | ||
data: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c634300080700330000000000000000000000000000000000000000000000000000000000010f2c' | ||
}) | ||
// { args: [69420n], bytecode: '0x6080604...' } | ||
``` | ||
|
||
```ts | ||
export const wagmiAbi = [ | ||
... | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'uint256', | ||
name: 'a', | ||
type: 'uint256', | ||
}, | ||
], | ||
stateMutability: 'nonpayable', | ||
type: 'constructor', | ||
}, | ||
... | ||
] as const; | ||
``` | ||
|
||
```ts [client.ts] | ||
import { createPublicClient, http } from 'viem' | ||
import { mainnet } from 'viem/chains' | ||
|
||
export const publicClient = createPublicClient({ | ||
chain: mainnet, | ||
transport: http() | ||
}) | ||
``` | ||
|
||
::: | ||
|
||
|
||
## Return Value | ||
|
||
```ts | ||
{ | ||
args: unknown[] | undefined; | ||
bytecode: Hex; | ||
} | ||
``` | ||
|
||
Decoded deploy data. | ||
|
||
## Parameters | ||
|
||
### abi | ||
|
||
- **Type:** [`Abi`](/docs/glossary/types#TODO) | ||
|
||
The contract's ABI. | ||
|
||
```ts | ||
const { args } = decodeFunctionData({ | ||
abi: wagmiAbi, // [!code focus] | ||
bytecode: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c63430008070033', | ||
data: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c634300080700330000000000000000000000000000000000000000000000000000000000010f2c' | ||
}) | ||
``` | ||
|
||
### bytecode | ||
|
||
- **Type:** `Hex` | ||
|
||
Contract bytecode. | ||
|
||
```ts | ||
const { args } = decodeFunctionData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c63430008070033', // [!code focus] | ||
data: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c634300080700330000000000000000000000000000000000000000000000000000000000010f2c' | ||
}) | ||
``` | ||
|
||
### data | ||
|
||
- **Type:** `Hex` | ||
|
||
The encoded calldata. | ||
|
||
```ts | ||
const { args } = decodeFunctionData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c63430008070033', | ||
data: '0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220116554d4ba29ee08da9e97dc54ff9a2a65d67a648140d616fc225a25ff08c86364736f6c634300080700330000000000000000000000000000000000000000000000000000000000010f2c' // [!code focus] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
976fd86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viem-benchmark – ./playgrounds/benchmark
viem-benchmark-git-main-wagmi-dev.vercel.app
viem-benchmark-wagmi-dev.vercel.app
viem-benchmark.vercel.app
976fd86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viem-playground – ./playgrounds/dev
viem-playground-wagmi-dev.vercel.app
viem-playground.vercel.app
viem-playground-git-main-wagmi-dev.vercel.app
976fd86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viem-site – ./site
viem-site-wagmi-dev.vercel.app
viem-site-git-main-wagmi-dev.vercel.app
viem-site.vercel.app