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

writeContract from viem doesn't work #112

Closed
flux0uz opened this issue Sep 7, 2023 · 3 comments
Closed

writeContract from viem doesn't work #112

flux0uz opened this issue Sep 7, 2023 · 3 comments

Comments

@flux0uz
Copy link

flux0uz commented Sep 7, 2023

The repo example works correctly (sendTransaction), but it's impossible to use the writeContract function. I get this error every time:

Details: the method is currently not implemented: eth_sendTransaction
  Version: [email protected]
      at delay.count.count (webpack-internal:///(actionBrowser)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/viem/dist/esm/utils/buildRequest.js:43:31)
      at async attemptRetry (webpack-internal:///(actionBrowser)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/viem/dist/esm/utils/promise/withRetry.js:21:30) {
    details: 'the method is currently not implemented: eth_sendTransaction',
    docsPath: undefined,
    metaMessages: [
      'URL: https://rpc.ankr.com/polygon_mumbai',
      'Request body: {"method":"eth_sendTransaction","params":[{"data":"0x97304ced00000000000000000000000000000000000000000000000000003691d6afc000","from":"0x54DBB70406f5BEA837CdD95A90E6002f4Fa2434c","to":"0x3c21eCEb9ef3F3c2440a37Ae969085Ea20999069"}]}'
    ],
    shortMessage: 'Missing or invalid parameters.\n' +
      'Double check you have provided the correct parameters.',
    version: '[email protected]',
    cause: RpcRequestError: RPC Request failed.
    
    URL: https://rpc.ankr.com/polygon_mumbai
    Request body: {"method":"eth_sendTransaction","params":[{"data":"0x97304ced00000000000000000000000000000000000000000000000000003691d6afc000","from":"0x54DBB70406f5BEA837CdD95A90E6002f4Fa2434c","to":"0x3c21eCEb9ef3F3c2440a37Ae969085Ea20999069"}]}

I use sub-organizations as custodial wallets.

Code to reproduce:

const turnkeyAccount = await createAccount({
      client: turnkeyClient,
      organizationId: subOrgId,
      privateKeyId: pkId,
    })

    const walletClient = createWalletClient({
      account: turnkeyAccount,
      chain: polygonMumbai,
      transport: http("https://rpc.ankr.com/polygon_mumbai"),
    }).extend(publicActions)

    const account = walletClient.account.address

    const { request } = await walletClient.simulateContract({
      address: "0x3c21eCEb9ef3F3c2440a37Ae969085Ea20999069",
      abi: [
        {
          inputs: [
            { internalType: "uint256", name: "supply", type: "uint256" },
          ],
          name: "mintTokens",
          outputs: [],
          stateMutability: "nonpayable",
          type: "function",
        },
      ] as const,
      functionName: "mintTokens",
      args: [bnAmount],
      account: account,
    })

    const hash = await walletClient.writeContract(request)
    console.log("Tx hash:", hash)

    const receipt = await walletClient.waitForTransactionReceipt({ hash })
    console.log("Tx receipt:", receipt)
    
@andrewkmin
Copy link
Collaborator

andrewkmin commented Sep 13, 2023

hi @flux0uz ! thanks for filing an issue (and apologies for the delayed response!). we're taking a look :)

@andrewkmin
Copy link
Collaborator

actually looking at https://www.ankr.com/rpc/polygon, i'm seeing the following:
image

i would recommend using a different node provider in the mean time, and/or filling an issue with viem to see if they can support eth_sendRawTransaction instead

@andrewkmin
Copy link
Collaborator

good news! viem actually added it relatively recently. you should be able to use sendRawTransaction. see docs here: https://github.com/wagmi-dev/viem/blob/main/site/docs/actions/wallet/prepareTransactionRequest.md#account-hoisting

and context on the PR as a whole here: wevm/viem#1058

will close this for now, but happy to reopen if issues persist!

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