-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
1,054 additions
and
53 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 Redstone chain. |
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
name: Snapshot | ||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
canary: | ||
name: Release snapshot version | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
id-token: write | ||
timeout-minutes: 5 | ||
|
||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: 'recursive' | ||
|
||
- name: Install dependencies | ||
uses: ./.github/actions/install-dependencies | ||
|
||
- name: Publish Snapshots | ||
continue-on-error: true | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# https://docs.npmjs.com/generating-provenance-statements | ||
NPM_CONFIG_PROVENANCE: true | ||
run: | | ||
snapshot=$(git branch --show-current | tr -cs '[:alnum:]-' '-' | tr '[:upper:]' '[:lower:]' | sed 's/-$//') | ||
npm config set "//registry.npmjs.org/:_authToken" "$NPM_TOKEN" | ||
bun run clean | ||
bun run changeset version --no-git-tag --snapshot $snapshot | ||
bun run changeset:prepublish | ||
bun run changeset publish --no-git-tag --snapshot $snapshot --tag $snapshot | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Installation | ||
|
||
Install Viem via your package manager, a `<script>` tag, or build from source. | ||
|
||
## Package Manager | ||
|
||
Install the required packages. | ||
|
||
:::code-group | ||
```bash [pnpm] | ||
pnpm add viem | ||
``` | ||
|
||
```bash [npm] | ||
npm install viem | ||
``` | ||
|
||
```bash [yarn] | ||
yarn add viem | ||
``` | ||
|
||
```bash [bun] | ||
bun add wagmi viem@{{viemVersion}} @tanstack/react-query | ||
``` | ||
::: | ||
|
||
## CDN | ||
|
||
If you're not using a package manager, you can also use Viem via an ESM-compatible CDN such as [esm.sh](https://esm.sh). Simply add a `<script type="module">` tag to the bottom of your HTML file with the following content. | ||
|
||
```html | ||
<script type="module"> | ||
import { createClient } from 'https://esm.sh/viem' | ||
</script> | ||
``` | ||
|
||
## Using Unreleased Commits | ||
|
||
If you can't wait for a new release to test the latest features, you can either install from the `canary` tag (tracks the [`main`](https://github.com/wevm/viem/tree/main) branch). | ||
|
||
:::code-group | ||
```bash [pnpm] | ||
pnpm add viem@canary | ||
``` | ||
|
||
```bash [npm] | ||
npm install viem@canary | ||
``` | ||
|
||
```bash [yarn] | ||
yarn add viem@canary | ||
``` | ||
|
||
```bash [bun] | ||
bun add viem@canary | ||
``` | ||
::: | ||
|
||
Or clone the [Viem repo](https://github.com/wevm/viem) to your local machine, build, and link it yourself. | ||
|
||
```bash | ||
gh repo clone wevm/viem | ||
cd viem | ||
bun install | ||
bun run build | ||
bun link --global | ||
``` | ||
|
||
Then go to the project where you are using Viem and run `bun link --global viem` (or the package manager that you used to link Viem globally). | ||
|
||
## Security | ||
|
||
Ethereum-related projects are often targeted in attacks to steal users' assets. Make sure you follow security best-practices for your project. Some quick things to get started. | ||
|
||
- Pin package versions, upgrade mindfully, and inspect lockfile changes to minimize the risk of [supply-chain attacks](https://nodejs.org/en/guides/security/#supply-chain-attacks). | ||
- Install the [Socket Security](https://socket.dev) [GitHub App](https://github.com/apps/socket-security) to help detect and block supply-chain attacks. | ||
- Add a [Content Security Policy](https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html) to defend against external scripts running in your app. | ||
|
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,171 @@ | ||
--- | ||
description: Request permissions from a wallet to perform actions on behalf of a user. | ||
--- | ||
|
||
# issuePermissions | ||
|
||
Request permissions from a wallet to perform actions on behalf of a user. | ||
|
||
[Read more.](https://eips.ethereum.org/EIPS/eip-7115) | ||
|
||
:::warning[Warning] | ||
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production. | ||
::: | ||
|
||
## Usage | ||
|
||
:::code-group | ||
|
||
```ts twoslash [example.ts] | ||
import { parseEther } from 'viem' | ||
import { account, walletClient } from './config' | ||
|
||
const result = await walletClient.issuePermissions({ // [!code focus:99] | ||
account, | ||
expiry: 1716846083638, | ||
permissions: [ | ||
{ | ||
type: 'native-token-limit', | ||
data: { | ||
amount: parseEther('0.5'), | ||
}, | ||
required: true, | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
```ts twoslash [config.ts] filename="config.ts" | ||
import 'viem/window' | ||
// ---cut--- | ||
import { createWalletClient, custom } from 'viem' | ||
import { mainnet } from 'viem/chains' | ||
import { walletActionsErc7115 } from 'viem/experimental' | ||
|
||
export const walletClient = createWalletClient({ | ||
chain: mainnet, | ||
transport: custom(window.ethereum!), | ||
}).extend(walletActionsErc7115()) | ||
|
||
export const [account] = await walletClient.getAddresses() | ||
``` | ||
|
||
::: | ||
|
||
## Returns | ||
|
||
`IssuePermissionsReturnType` | ||
|
||
Response from the wallet after issuing permissions. | ||
|
||
## Parameters | ||
|
||
### account | ||
|
||
- **Type:** `Account | Address | undefined` | ||
|
||
The Account to scope the permissions to. | ||
|
||
```ts twoslash | ||
import { parseEther } from 'viem' | ||
import { account, walletClient } from './config' | ||
|
||
const result = await walletClient.issuePermissions({ | ||
account, // [!code focus] | ||
expiry: 1716846083638, | ||
permissions: [ | ||
{ | ||
type: 'native-token-limit', | ||
data: { | ||
amount: parseEther('0.5'), | ||
}, | ||
required: true, | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
### expiry | ||
|
||
- **Type:** `number` | ||
|
||
The timestamp (in seconds) when the permissions will expire. | ||
|
||
```ts twoslash | ||
import { parseEther } from 'viem' | ||
import { account, walletClient } from './config' | ||
|
||
const result = await walletClient.issuePermissions({ | ||
account, | ||
expiry: 1716846083638, // [!code focus] | ||
permissions: [ | ||
{ | ||
type: 'native-token-limit', | ||
data: { | ||
amount: parseEther('0.5'), | ||
}, | ||
required: true, | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
### permissions | ||
|
||
- **Type:** `Permission[]` | ||
|
||
Set of permissions to grant to the user. | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { parseEther } from 'viem' | ||
import { account, walletClient } from './config' | ||
|
||
const result = await walletClient.issuePermissions({ | ||
account, | ||
expiry: 1716846083638, | ||
permissions: [ // [!code focus:99] | ||
{ | ||
type: 'native-token-limit', | ||
data: { | ||
amount: parseEther('0.5'), | ||
}, | ||
required: true, | ||
}, | ||
{ | ||
type: ' | ||
// ^| | ||
} | ||
], | ||
}) | ||
``` | ||
|
||
### signer | ||
|
||
- **Type:** `Signer | undefined` | ||
|
||
Custom signer type to scope the permissions to. | ||
|
||
```ts twoslash | ||
import { parseEther } from 'viem' | ||
import { account, walletClient } from './config' | ||
|
||
const result = await walletClient.issuePermissions({ | ||
expiry: 1716846083638, | ||
permissions: [ | ||
{ | ||
type: 'native-token-limit', | ||
data: { | ||
amount: parseEther('0.5'), | ||
}, | ||
required: true, | ||
}, | ||
], | ||
signer: { // [!code focus] | ||
type: 'key', // [!code focus] | ||
data: { // [!code focus] | ||
id: '...' // [!code focus] | ||
} // [!code focus] | ||
} // [!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
Oops, something went wrong.