0

Hello i Make my wallet to be recognized by the dapps under the name of phantom. When connect request is send from the dapp i successfully initialize my public key but then dapps freezes. Example with MagicEden:

Magic Eden Address stuck on loading

Currently my implementation looks like this :

 this.window.solana = {
      isPhantom: true,
      isConnected: false,
      publicKey: null,
      connect: async () => {
        const { accepted } = await this.window.providerManager.enable('solana')
        const solana = this.window.providerManager.getProviderFor('SOL')
        const addresses = await solana.getMethod('wallet.getAddresses')()
        const [address] = addresses;
        const { publicKey } = address;

        console.log('wowz', address)
        this.isConnected = true
        this.publicKey = new PublicKey(publicKey);
      },
      on: async (method, payload) => {
        console.log('ON Method ', method)
        console.log('ON Payload ', payload)
        


      },
      accountChanged: async () => {
        console.log('accountChanged')
      },
      off: async (method, payload) => {
        console.log('OFF Method ', method)
        console.log('OFF Payload ', payload)
      },
      disconnect: () => {
        console.log('dc called')
      },

    }

Any idea what i'm doing wrong? I feel is like something with how i return the response to the dapp but really not sure how to do it, also other wallets are not open source and can't debug them. Please heeelp

1

1 Answer 1

1

This is a very specific implementation question about a specific wallet (Phantom) that you are trying to mimic on a specific app (MagicEden). It sometimes helps to frame your question in a more general way, and indicate what research you have done into the problem.

Let's suppose your question is "How can I build a wallet with Phantom's API?" This is of course both a very trivial question and a very not trivial question at the same time :)

In answer to the trivial version, almost every wallet on Solana has an adapter in the Wallet Adapter repo that describes the interface of the wallet on the window. Here is the one for Phantom.

To mimic Phantom's API, simply create an object that implements this interface. You can use those types to know whether your object conforms to the interface. This tells you less about the behavior, but at least will get you on the right track.

The non-trivial answer is of course that building a browser extension wallet is a lot of work! There's a lot of prior art, which you should seek to understand. Fortunately there are some open source wallets with APIs similar to Phantoms (and also have Wallet Adapter TypeScript interfaces). I would take a look at Alpha Wallet and Salmon Wallet (which is itself an updated fork of Sollet).

1
  • Thanks bro thats really helpful information, respect! I'm building the injection module and the particular issue that i face is returning the response to the dapp. I tried provided examples with window.postMessage but seems like is not working under phantom context, trying to figure out what are these on and off listeners for phantom Sep 16, 2022 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.