Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrations/viem: initial package work #268

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[wip] Viem example
  • Loading branch information
aefhm committed Jan 31, 2024
commit de44aa18caf6d6075bc5dc90466a39ba1a19e254
1 change: 1 addition & 0 deletions examples/viem/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
20 changes: 20 additions & 0 deletions examples/viem/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "example-viem",
"private": true,
"type": "module",
"main": "lib/index.js",
"scripts": {
"build": "tsc -b",
"test": "tsc -b && pnpm node build/index.js"
},
"dependencies": {
"@oasisprotocol/sapphire-paratime": "workspace:^",
"viem": "2.6.1"
},
"devDependencies": {
"@types/node": "^17.0.10",
"@tsconfig/strictest": "2.0.2",
"ts-node": "10.9.2",
"typescript": "5.3.3"
}
}
47 changes: 47 additions & 0 deletions examples/viem/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// import { wrap } from "@oasisprotocol/sapphire-paratime";
import { http, createWalletClient, Hex } from 'viem';

import OmnibusJSON from "../../../contracts/artifacts/contracts/tests/Omnibus.sol/Omnibus.json" assert { type: "json" };
import { privateKeyToAccount } from "viem/accounts";

const LOCAL_NET = {
id: 23293,
name: 'Oasis Sapphire Testnet',
network: 'sapphire-testnet',
nativeCurrency: { name: 'Sapphire Test Rose', symbol: 'TEST', decimals: 18 },
rpcUrls: {
default: {
http: ['http://127.0.0.1:8545'],
},
public: {
http: ['http://127.0.0.1:8545'],
},
},
testnet: true,
};

async function main () {
const account = privateKeyToAccount('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80');
const provider = http('http://127.0.0.1:8545');

// TODO actually wrap provider or use integration to extend client
// const wrapped = wrap(provider as EIP1193Provider);
const walletClient = createWalletClient({
account,
chain: LOCAL_NET,
transport: provider
});

const hash = await walletClient.deployContract({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be using Viem right. I get a deploy error.

TransactionExecutionError: The method does not exist / is not available.
...
Details: the method eth_sendTransaction does not exist/is not available
Version: [email protected]
    at getTransactionError (file:///Users/xi/oasis/sapphire-paratime/node_modules/.pnpm/[email protected][email protected]/node_modules/viem/_esm/utils/errors/getTransactionError.js:11:12)
    at sendTransaction (file:///Users/xi/oasis/sapphire-paratime/node_modules/.pnpm/[email protected][email protected]/node_modules/viem/_esm/actions/wallet/sendTransaction.js:123:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (file:///Users/xi/oasis/sapphire-paratime/examples/viem/build/examples/viem/src/index.js:38:18)
    at async file:///Users/xi/oasis/sapphire-paratime/examples/viem/build/examples/viem/src/index.js:73:1 {
  details: 'the method eth_sendTransaction does not exist/is not available',
  docsPath: undefined,
  metaMessages: [
    'URL: http://127.0.0.1:8545',
    'Request body: {"method":"eth_sendTransaction","params":[{"data":"...","from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}]}',
    ' ',
    'Request Arguments:',
    '  chain:  Oasis Sapphire Testnet (id: 23293)\n' +
      '  from:   0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266\n' +
      '  data:  ...'
  ],
  shortMessage: 'The method does not exist / is not available.',
  version: '[email protected]',
  cause: MethodNotFoundRpcError: The method does not exist / is not available.
  
  URL: http://127.0.0.1:8545

abi: OmnibusJSON.abi,
account: account.address,
chain: LOCAL_NET,
bytecode: OmnibusJSON.bytecode as Hex,
});

console.log(hash)

// TODO migrate additional ethers integration tests over
}

await main ();
14 changes: 14 additions & 0 deletions examples/viem/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"outDir": "./build",
"module": "NodeNext",
"target": "ES2022",
"moduleResolution": "NodeNext",
"resolveJsonModule": true
},
"include": [
"./src"
]
}
90 changes: 82 additions & 8 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ packages:
- examples/hardhat
- examples/ethersv5-ts-esm
- examples/ethersv6-ts-esm
- examples/viem
- examples/web3js-ts-esm
- examples/hardhat-boilerplate
- examples/hardhat-boilerplate/frontend
Loading