Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dutterbutter/min-viem-example
https://github.com/dutterbutter/min-viem-example
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dutterbutter/min-viem-example
- Owner: dutterbutter
- License: mit
- Created: 2023-08-11T16:56:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-19T20:24:22.000Z (about 1 year ago)
- Last Synced: 2024-04-14T04:07:07.898Z (7 months ago)
- Language: TypeScript
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Viem & Paymaster: A Minimal Example
This repository provides a concise example to highlight the challenges faced when integrating paymasters with `viem`. While `ethers.js` has supported paymasters (as discussed [here](https://github.com/ethers-io/ethers.js/issues/1761) and completed [here](https://github.com/ethers-io/ethers.js/commit/68095a48ae19ed06cbcf2f415f1fcbda90d4b2ae)), we should be advocating for similar improvements to be made in the `viem` framework.
## Comparing Ethers.js and Viem
In `ethers.js`, using paymasters is used similarly as:
```javascript
const tx = await contract.myFunction(
...args, // regular arguments for the contract method
{
gasLimit: 30000, // standard override
custom: { customField: "abacaba" } // custom override
}
);
```While the desired implementation in `viem` would ideally look like this:
```javascript
const data = await walletClient.writeContract({
address: "0xbe9bcf56654fd81a921b6Bd07965Dd67Afbb0B69",
abi: ContractArtifact.abi,
functionName: "setGreeting",
account,
args: ["Hello World!"],
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
paymasterParams,
},
});
```## Getting Started
### Prerequisites
Ensure you have `yarn` or `pnpm` installed.
### Run example
1. Change directories:
```bash
cd write-contract-example
```2. Install the required dependencies:
```bash
pnpm install
```3. Run development server:
```bash
pnpm dev
```**Note:** There's no requirement to compile or deploy contracts for this example. The script utilizes contracts previously deployed on the zkSync Era testnet.
## Debugging
For improved debugging I suggest using a local copy of viem so you may add console logs etc. For example,
```
"dependencies": {
"viem": "file:",
"vite": "^4.4.9"
}
```