Make the newly created wallet visible on the chain

Any example as to how can I fund a newly created wallet using typescript sdk

2 Likes

Hey @shivamlync, our documentation has plenty of examples of working with wallets with the TS SDK.

But you can generate and get the bech32 address of a wallet like so:

import { Wallet, Provider, FUEL_NETWORK_URL } from 'fuels';

const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = Wallet.generate({ provider });
const address = wallet.address.toString();
// fuel...

Then you can fund that wallet using the faucet.

2 Likes

Is it possible to fund the newly created wallet using the ts sdk

Also, can you please elaborate the parameters in each function provided in the ts SDK, as what values to pass in that function or the type that the function has needs to be referred either from the function’s declaration part from the SDK by going inside the function or on the github section.

Which function are you referring to? We also have API documentation which you may find helpful for function parameters and their types. Or I’d recommend a TS extension with type hinting for your IDE.

1 Like
 const provider = await Provider.create(FUEL_BETA_5_NETWORK_URL);

  const unlockedWallet: WalletUnlocked = Wallet.generate({ provider });
  
  const fund = unlockedWallet.fund(request, coinQuantities, fee) // here what does these parameters define? like what request or what values to pass in the request...
1 Like

in the api doc the fund function is not there.

1 Like

So we are using fund to fund the transaction. The first parameter request, is the transaction request that you are building, the second parameter coinQuantities are the coins that you’d like to fund the transaction with.

If you set your documentation version to nightly, and check out this cookbook, it provides a great example on building out a transaction and funding it using fund, to then call contract functions.

2 Likes

So I can’t fund a newly created wallet with some test faucets using the ts SDK. I’ll have to ask the user to use the faucet and fund it by himself.

You can transfer assets between wallets, if you already have a wallet with funds and a newly created wallet. One wallet will definitely require funds already, whether that came from the faucet or was transferred from a funded wallet.

This documentation on wallet transferring should help.

2 Likes

what is the assetId value here

Here we are transferring the base asset, this is dictated by the chain.

import { Provider } from 'fuels';

const provider = await Provider.create(FUEL_BETA_5_NETWORK_URL);
const baseAssetId = provider.getBaseAssetId();

This was included in fuels@0.83.0. If you are running an earlier version you can just import it, like so:

import { BaseAssetId } from 'fuels';

But please note, this value could be subject to change per network. But if you are beta-5 or the default local chain config, you are okay to use the constant.

1 Like

I don’t want to use my or any other external wallet to fund the newly created wallet. Is it possible to do the funding process without the need to use any external wallets?

As the faucet provides 0.002 ETH faucet for some time which might be less for multiple transactions. The wait is a bit long. So

AFAIK your options right now are faucet, bridge or using another wallet.

1 Like

Something like this work ?

const provider = await Provider.create(FUEL_BETA_5_NETWORK_URL);

  const myWallet = Wallet.fromPrivateKey(
    <Private Key of the faucet wallet>,
    provider
  );

  const recipient: WalletUnlocked = Wallet.generate({ provider });
  console.log("5", recipient.address.toString());

  const txResponse = await myWallet.transfer(
    recipient.address,
    100,
    BaseAssetId
  );

  await txResponse.waitForResult();

  const transactionSummary = await txResponse.getTransactionSummary();

  return res.status(200).json({
    hash: transactionSummary.id,
    walletAddress: recipient.address.toString(),
  });
1 Like

@danielbate
Any way one could get more than this?

Yes that would work :+1:

You could wrap the transfer in a try catch block if you did want to try catch instances where your faucet wallet has run dry and return a different error, rather than the not enough coins to fit the target error that we currently through.