-
-
Notifications
You must be signed in to change notification settings - Fork 961
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
20 changed files
with
409 additions
and
21 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 `encodeDeployData`. |
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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,146 @@ | ||
# encodeDeployData | ||
|
||
Encodes deploy data (bytecode & constructor args) into an ABI encoded value. | ||
|
||
## Install | ||
|
||
```ts | ||
import { encodeDeployData } from 'viem' | ||
``` | ||
|
||
## Usage | ||
|
||
Below is a very basic example of how to encode deploy data. | ||
|
||
::: code-group | ||
|
||
```ts [example.ts] | ||
import { encodeDeployData } from 'viem' | ||
|
||
const data = encodeDeployData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...' | ||
}) | ||
// 0x608060405260405161083e38038061083e833981016040819052610... | ||
``` | ||
|
||
```ts | ||
export const wagmiAbi = [ | ||
... | ||
{ | ||
inputs: [], | ||
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() | ||
}) | ||
``` | ||
|
||
::: | ||
|
||
### Passing Arguments | ||
|
||
If your constructor requires argument(s), you can pass them through with the `args` attribute. | ||
|
||
TypeScript types for `args` will be inferred from the constructor & ABI, to guard you from inserting the wrong values. | ||
|
||
For example, the `constructor` below requires an **address** argument, and it is typed as `["0x${string}"]`. | ||
|
||
::: code-group | ||
|
||
```ts {8} [example.ts] | ||
import { encodeFunctionData } from 'viem' | ||
import { publicClient } from './client' | ||
import { wagmiAbi } from './abi' | ||
|
||
const data = encodeFunctionData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...', | ||
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'] | ||
}) | ||
// 0x608060405260405161083e38038061083e833981016040819052610...00000000000000000000000000000000a5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC | ||
``` | ||
|
||
```ts [abi.ts] | ||
export const wagmiAbi = [ | ||
... | ||
{ | ||
inputs: [{ name: 'owner', type: 'address' }], | ||
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 | ||
|
||
`Hex` | ||
|
||
ABI encoded data (bytecode & constructor arguments). | ||
|
||
## Parameters | ||
|
||
### abi | ||
|
||
- **Type:** [`Abi`](/docs/glossary/types#TODO) | ||
|
||
The contract's ABI. | ||
|
||
```ts | ||
const data = encodeFunctionData({ | ||
abi: wagmiAbi, // [!code focus] | ||
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...', | ||
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'] | ||
}) | ||
``` | ||
|
||
### bytecode | ||
|
||
- **Type:** `Hex` | ||
|
||
Contract bytecode. | ||
|
||
```ts | ||
const data = encodeFunctionData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...', // [!code focus] | ||
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'] | ||
}) | ||
``` | ||
|
||
### args (optional) | ||
|
||
- **Type:** Inferred from ABI. | ||
|
||
Arguments to pass to function call. | ||
|
||
```ts | ||
const data = encodeFunctionData({ | ||
abi: wagmiAbi, | ||
bytecode: '0x608060405260405161083e38038061083e833981016040819052610...', | ||
args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'] // [!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
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.
94b32ab
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-wagmi-dev.vercel.app
viem-benchmark-git-main-wagmi-dev.vercel.app
viem-benchmark.vercel.app
94b32ab
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-git-main-wagmi-dev.vercel.app
viem-site-wagmi-dev.vercel.app
viem-site.vercel.app
94b32ab
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-git-main-wagmi-dev.vercel.app
viem-playground.vercel.app
viem-playground-wagmi-dev.vercel.app