0

I'm starting to get interested on Web3 development, and I'd like to get some advices to help me on this journey. Well, following this amazing tutorial I've created a token on the Solana blockchain and I have these questions about what can I do on Web3 frontend development:

  • Is it possible to get the user's wallets addresses once he's authenticated on Phantom?
  • Is it possible to get the amount of tokens that the user has on its wallets?
  • Assuming that my token isn't on an exchange, but I have 100 units of it and I want to transfer 50 units to another wallet, would it be possible to happen?

And the last but event important, I'd like to know which tecnologies, articles, websites and etc can help me build this and also learn about these topics?

TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

2

Is it possible to get the user's wallet addresses once he's connected to Phantom?

Yes! With the wallet-adapter you can retrieve the connected publicKey and get the connected token addresses.

Example:

const { connection } = useConnection();
const { publicKey } = useWallet();

const tokenAccounts = await connection.getParsedTokenAccountsByOwner(publicKey, { programId: TOKEN_PROGRAM_ID });

Is it possible to get the amount of tokens that the user has on its wallets?

If you console.log the above example:

const tokenAccounts = await connection.getParsedTokenAccountsByOwner(new PublicKey('Ccyrkw1FdRVsfnt7qptyUXqyffq3i59GSPN1EULqZN6i'), { programId: TOKEN_PROGRAM_ID });

tokenAccounts.value.forEach((accountInfo) => {
    console.log(`pubkey: ${accountInfo.pubkey.toBase58()}`)
    console.log(`mint: ${accountInfo.account.data["parsed"]["info"]["mint"]}`);
    console.log(`owner: ${accountInfo.account.data["parsed"]["info"]["owner"]}`);
    console.log(`decimals: ${accountInfo.account.data["parsed"]["info"]["tokenAmount"]["decimals"]}`);
    console.log(`amount: ${accountInfo.account.data["parsed"]["info"]["tokenAmount"]["amount"]}`);
    console.log("====================")
  });

/*
pubkey: ArbSRRSPZ5SqXjyjcip3UUZ55Eqn5AkCP4dHZNRrKBhz
mint: 8HGyAAB1yoM1ttS7pXjHMa3dukTFGQggnFFH3hJZgzQh
owner: Ccyrkw1FdRVsfnt7qptyUXqyffq3i59GSPN1EULqZN6i
decimals: 6
amount: 875471
====================
pubkey: 6JbMNzmX7QrxUEL5RT9TczvTuCjXPFTDRWgCs88atmV8
mint: 4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R
owner: Ccyrkw1FdRVsfnt7qptyUXqyffq3i59GSPN1EULqZN6i
decimals: 6
amount: 330108
====================
pubkey: 9xqnnfeonbsEGSPgF5Wd7bf9RqXy4KP22bdaGmZbHGwp
mint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
owner: Ccyrkw1FdRVsfnt7qptyUXqyffq3i59GSPN1EULqZN6i
decimals: 6
amount: 199497145
====================
*/

Assuming that my token isn't on an exchange, but I have 100 units of it and I want to transfer 50 units to another wallet, would it be possible to happen?

Yep, you can transfer tokens between wallets as well.

let tx = new Transaction().add(
      createTransferCheckedInstruction(
        tokenAccountXPubkey, // from (should be a token account)
        mintPubkey, // mint
        tokenAccountYPubkey, // to (should be a token account)
        alice.publicKey, // from's owner
        50e8, // amount, if your deciamls is 8, send 10^8 for 1 token
        8 // decimals
      )
    );
await sendAndConfirmTransaction(connection, tx, [alice]);

I'd like to know which technologies, articles, websites and etc can help me build this and also learn about these topics?

There's a bunch of great material with examples over at the Solana Cookbook. Otherwise I would refer to the answers the other user has given.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jacob Creech
  • 1,797
  • 2
  • 11
1

Is it possible to get the user's wallets addresses once he's authenticated on Phantom?

Yes ! this is possibly. Similar to metamask you can refer phantom SDK in order to get the user's public wallet address

Regarding Transfer, it is possible but, you have to use metaplex for transferring your tokens from one wallet to another.

Is it possible to get the amount of tokens that the user has on its wallets?

For this, you have to do some R and D because it is kind of privacy issue to list all the wallet tokens of the user.

And for Web3.js Resources you can refer

  1. Build Space
  2. Solana Labs Github Repo
  3. Chainlink Tutorial
  4. Youtube channel :- Dapps Academy
  5. https://dev.to/jebitokdev/getting-started-with-web3-communities-and-resources-kce
TylerH
  • 20,799
  • 66
  • 75
  • 101
Sudarshan
  • 702
  • 6
  • 24