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

err.walk is not a function #121

Open
davidlee1435 opened this issue Sep 22, 2023 · 2 comments
Open

err.walk is not a function #121

davidlee1435 opened this issue Sep 22, 2023 · 2 comments

Comments

@davidlee1435
Copy link

davidlee1435 commented Sep 22, 2023

Hi all, I'm using Turnkey with Viem and running into an issue when trying to call writeContract. I suspect it's an error with Turnkey and not Viem because I am able to use Viem's privateKeyToAccount to successfully call writeContract.

Here's the part of the TypeScript script that I have that's throwing the error:

  const turnkeyClient = new TurnkeyClient(
    {
      baseUrl: TurnkeyConfig.baseUrl,
    },
    new ApiKeyStamper({
      apiPublicKey: TurnkeyConfig.apiPublicKey,
      apiPrivateKey: process.env.TURNKEY_API_PRIVATE_KEY,
    }),
  );

  const account = await createAccount({
    client: turnkeyClient,
    organizationId: TurnkeyConfig.organizationId,
    privateKeyId: TurnkeyConfig.privateKeyIds.minter,
  });

  const publicClient = createPublicClient({
    chain,
    transport: http(),
  });

  const walletClient = createWalletClient({
    account,
    chain,
    transport: http(),
  });
  
  // This returns a correct response
  const { request } =
    await publicClient.simulateContract({
      account,
      <my address>,
      abi: myErc20ABI,
      functionName: "mint",
      args: [recipient, amount],
    });

  const hash = await walletClient.writeContract(request);

Stack trace:

[Uncaught Error]: err.walk is not a function

TypeError: err.walk is not a function
    at getNodeError (/Users/davidlee/dev/peregrine/stable/packages/scripts/node_modules/viem/utils/errors/getNodeError.ts:36:38)
    at getTransactionError (/Users/davidlee/dev/peregrine/stable/packages/scripts/node_modules/viem/utils/errors/getTransactionError.ts:23:27)
    at sendTransaction (/Users/davidlee/dev/peregrine/stable/packages/scripts/node_modules/viem/actions/wallet/sendTransaction.ts:185:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async writeContract (/Users/davidlee/dev/peregrine/stable/packages/scripts/node_modules/viem/actions/wallet/writeContract.ts:133:16)
    at async processCommand (/Users/davidlee/dev/peregrine/stable/packages/scripts/src/mint-usdlr.ts:83:16)

Dependency versions:

"@turnkey/api-key-stamper": "^0.1.1",
"@turnkey/http": "^1.2.0",
"@turnkey/viem": "^0.2.4",
"viem": "^1.11.0"

Let me know if I should add any other information!

@davidlee1435
Copy link
Author

davidlee1435 commented Sep 25, 2023

After trying to call the same function with @turnkey/ethers, it seems the root cause was because my (misconfigured) policy engine denied my request:

[Uncaught Error]: Failed to sign: Turnkey error 7: policy engine denied request implicitly (Details: [])

TurnkeyActivityError: Failed to sign: Turnkey error 7: policy engine denied request implicitly (Details: [])
    at TurnkeySigner._signTransactionWithErrorWrapping (/Users/davidlee/dev/peregrine/stable/node_modules/@turnkey/ethers/src/index.ts:112:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TurnkeySigner.signTransaction (/Users/davidlee/dev/peregrine/stable/node_modules/@turnkey/ethers/src/index.ts:146:22)

Hope this adds some color for a fix!

@timurnkey
Copy link
Contributor

Glad you were able to find a fix. It looks like the viem API was swallowing the errors because they expect a specific error: BaseError with a method walk(). Will see if there's anything we can do on our side to improve this UX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants