Fuel address format in GraphQL queries

In a previous Q&A, @calldelegation shared the following example GraphQL query:

query {
  balances(filter: { owner: "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871" }, first: 5) {
    nodes {
      amount
      assetId
    }
  }
}

I can see that the same address is used throughout the example queries in your GraphQL docs.

But this confuses me because the address format does not match what I see in my Fuel wallet, which is this:

fuel1s0cvmmdgpjmrc48vv306rcqmv2ug3ua0z0qj509ptewvvj864mvs08zs42

Passing this value in the GraphQL query results in an error:

{
  "data": null,
  "errors": [
    {
      "message": "Failed to parse \"Address\": Odd number of digits (occurred while parsing \"BalanceFilterInput\")",
      "locations": [
        {
          "line": 2,
          "column": 20
        }
      ],
      "path": [
        "balances"
      ]
    }
  ]
}

How am I supposed to convert my wallet’s Fuel address to the format expected by the GraphQL server?

2 Likes

Based on the discussion here, I think I am getting it now.

What I need for the GraphQL query is the hex address, whereas the Fuel Wallet displays only the Bech32 address (and there’s no way to view the address as hex, unfortunately).

But it looks like I can export the private key using the Fuel Wallet. Is there any CLI tool that I can use for deriving the public key?

Edit: I tried to generate the public key using this browser-based ED25519 tool, but the generated value didn’t seem to match my actual address (the query returned a balance of zero, whereas I have ~0.449 ETH on Testnet Beta 3).

1 Like

Hi there!
You can use the TS sdk to get the hex address.

      const wallet = await window.fuel.getWallet(account);
      console.log("wallet: ", wallet.address, wallet.address.toHexString());

2 Likes

I’ll add that our goal is to use Bech32 everywhere, but we’ve done a poor job at being consistent with it’s usage :disappointed:

The GraphQL RPC should definitely should have Bech32 support added to it.

2 Likes

Hello @prberg, I am working on a crypto plugin for forc.

Once that plugin is available, it would be possible to perform all the conversion that you need right at your cli.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.