0

I have a web service in which I'll be generating to my users wallets in SOL and in USDT/USDC. The wallets will be custodial, for deposits, and it has to be this way.

And I need to obtain and parse incoming TXs in SOL and USDT/USDC, via API.

As I've found out, in order be able to see and parse incoming TXs in USDT/USDC, I'll have to create and use the 2 assosiated accounts for USDT/USDC first. In other words, the API endpoint getSignaturesForAddress(...), if called with the main - SOL - address, will only return the TXs sent in SOL, and not the ones send in USDT/USDC.

To parse the TXs for the tokens, getSignaturesForAddress(spl_token_addrr) requires an address of any of those.

Correct?

If so, how will I resolve all this?

Will I have to generate the main - SOL - account first, for each new wallet, then top it up to pay the rent (0.005 SOL), and only then generate assosiated addresses in USDT/USDC for it?

How to generate an assosiated account in web3.js?


Otherwise, is there a better and simpler solution?

update 1:

if a user for the very time sends some USDT to the SOL address, thus creating a USDT address by himself, this will work fine. However, how will I check and get the address of, not create it, an assossiated account for USDT by the main SOL one?

1 Answer 1

1

i'm not 100% sure to get your question properly, but you can get the associated token account address with this code :

    import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from '@solana/spl-token';

export async function getAssociatedTokenAccount(mint, owner) {
  
  const tokenAccount = await getAssociatedTokenAddress(
        mint,
        owner,  
        true,
        TOKEN_PROGRAM_ID,
        ASSOCIATED_TOKEN_PROGRAM_ID,
    );
  
  return tokenAccount;
}

please note that this code will always return an address, even if it doesn't exists.

If you need it to be created, you have to check by yourself if it exists and you can create it if needed.

If i understood properly your use case, you have to create first a wallet address, then you can create the associated token accounts. IMO, there is no need to have SOL in the wallet - not sure about this though.

If a user sends USDT/USDC first, this should create the associated token account (depends on how it is sent, because the user has to funds those accounts, so if this is sent with phantom for example, it should be done automaticaly)

10
  • my goal, ideally, is to generate USDT/USDC addresses right after I've generated the main address in SOL and do so without having to deposit any SOL for this. Is it possible? Later on I or a user will deposit some SOLs to it
    – Camila326
    Commented Sep 13, 2023 at 0:17
  • please note that this code will always return an address, even if it doesn't exists. -- if called multiple times, wil an address come out different each time? Provided it's not been properly created yet
    – Camila326
    Commented Sep 13, 2023 at 0:19
  • 1) you can't create the accounts without spending sol. 2) it should return always the same address, even if not created.
    – Effe2
    Commented Sep 13, 2023 at 1:08
  • 2) if the main account is empty, I could generate an address for USDT, give it to a user, he'll send USDT to it and he'll also get charged by the network automatically for creating or activating an account. Correct?
    – Camila326
    Commented Sep 13, 2023 at 2:52
  • how your user will send usdt ? With a wallet (like phantom for example) ?
    – Effe2
    Commented Sep 13, 2023 at 6:25

Your Answer

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

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