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

bug: ethers wallet send transactions not working #319

Closed
1 task done
songkeys opened this issue Apr 6, 2023 · 3 comments · Fixed by #322
Closed
1 task done

bug: ethers wallet send transactions not working #319

songkeys opened this issue Apr 6, 2023 · 3 comments · Fixed by #322
Assignees

Comments

@songkeys
Copy link
Contributor

songkeys commented Apr 6, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

0.2.9

Current Behavior

/Users/songkeys/GitHub/playground/node_modules/viem/dist/chunk-XMKUHSC7.js:3321
  return new TransactionExecutionError(cause, {
         ^

TransactionExecutionError: An error occurred.

Request Arguments:
  from:  0x00000081d48bA02DAa6C13D55C2916aD0570B652
  to:    0xa6f969045641Cf486a747A2688F3a5A6d43cd0D8
  data:  0xcd69fe61000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000081d48ba02daa6c13d55c2916ad0570b65200000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000001a612d72616e646f6d2d68616e646c652d797265746a3374323538000000000000000000000000000000000000000000000000000000000000000000000000003c697066733a2f2f516d544d4436734c41374d346965674b446862644d50425a34484c6935666a57323777324a3136677163354362372f312e6a736f6e0000000000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000

Details: invalid object key - account (argument="transaction:account", value="[object Object]", code=INVALID_ARGUMENT, version=properties/5.7.0)
Version: viem@0.1.19
    at getTransactionError (/Users/songkeys/GitHub/playground/node_modules/viem/dist/chunk-XMKUHSC7.js:3321:10)
    at sendTransaction (/Users/songkeys/GitHub/playground/node_modules/viem/dist/chunk-XMKUHSC7.js:5090:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async writeContract (/Users/songkeys/GitHub/playground/node_modules/viem/dist/chunk-XMKUHSC7.js:5224:17)

Expected Behavior

Sent tx successfully.

Steps To Reproduce

I posted this here a month ago. Now, I tried again. it's the same error in 0.2.x.

I follow this guide to writeContract, and this guide to convert ethers wallet to viem.

Code to reproduce:

import { Wallet } from 'ethers'; // v5
import { createWalletClient, createPublicClient, http } from 'viem';
import { ethersWalletToAccount } from 'viem/ethers';
import { crossbell } from 'viem/chains';

const walletClient = createWalletClient({
  chain: crossbell,
  transport: http('https://rpc.crossbell.io'),
});
const publicClient = createPublicClient({
  chain: crossbell,
  transport: http('https://rpc.crossbell.io'),
});
const wallet = new Wallet(
  privateKey, // you may need to claim the gas from https://faucet.crossbell.io
);
const account = ethersWalletToAccount(wallet);

const { request } = await publicClient.simulateContract({
  account,
  address: '0xa6f969045641Cf486a747A2688F3a5A6d43cd0D8',
  abi: [
    {
      inputs: [
        {
          components: [
            {
              internalType: 'address',
              name: 'to',
              type: 'address',
            },
            {
              internalType: 'string',
              name: 'handle',
              type: 'string',
            },
            {
              internalType: 'string',
              name: 'uri',
              type: 'string',
            },
            {
              internalType: 'address',
              name: 'linkModule',
              type: 'address',
            },
            {
              internalType: 'bytes',
              name: 'linkModuleInitData',
              type: 'bytes',
            },
          ],
          internalType: 'struct DataTypes.CreateCharacterData',
          name: 'vars',
          type: 'tuple',
        },
      ],
      name: 'createCharacter',
      outputs: [
        {
          internalType: 'uint256',
          name: 'characterId',
          type: 'uint256',
        },
      ],
      stateMutability: 'nonpayable',
      type: 'function',
    },
  ],
  functionName: 'createCharacter',
  args: [
    {
      to: wallet.address,
      handle: genRandomHandle(),
      uri: 'fake-url',
      linkModule: '0x0000000000000000000000000000000000000000',
      linkModuleInitData: '0x0000000000000000000000000000000000000000',
    },
  ],
});
const hash = await walletClient.writeContract(request);

export { hash };

// util
function genRandomHandle() {
  const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
  let handle = '';
  for (let i = 0; i < 10; i++) {
    handle += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return 'a-random-handle-' + handle;
}

image

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

https://stackblitz.com/edit/viem-getting-started-rjwzad?file=index.ts

Anything else?

If you need anything else (like gas to test or additional private info), you may contact me on discord Songkeys#0001 or telegram.

@jxom
Copy link
Member

jxom commented Apr 6, 2023

Ah. We need to omit the account property in the Ethers adapter. Can fix when I’m back at the computer!

You could probably just use privateKeyToAccount now (added in 0.2). We will probably remove the ethers adapter in a future version as our private key implementation has parity.

@songkeys
Copy link
Contributor Author

songkeys commented Apr 6, 2023

Just tried privateKeyToAccount, it works good! You were right. I think we don't need the ethers adpter if we have this.

Copy link
Contributor

github-actions bot commented Jun 3, 2024

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Viem version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants