1

I would like to create other address/accounts belonging to my initial account, the goal is to have several separate addresses and carry out transactions by paying the fees from my main accounts.

It's like the exchanges create accounts that belong to them and they make transactions between by paying the fees. This is my example:

// BANK or Exchange
  const BankaccountKeypair = web3.Keypair.fromSecretKey([160,15,25, ...]);
  const BANK_wallet = splEasy.Wallet.fromKeypair(connection,BankaccountKeypair);

// Customer A (to)
  const A_wallet = splEasy.Wallet.fromKeypair(connection,web3.Keypair.fromSecretKey([20,18,125, ...]));

var myToken = new splToken.Token(
    connection,
    new web3.PublicKey('TRmbtbEW4g.......'),
    splToken.TOKEN_PROGRAM_ID,
    BANK_wallet 
  );

  // A account (to)
  var A_walletAccount = await myToken.getOrCreateAssociatedAccountInfo( A_wallet.publicKey );


// B account(from)
  const B_walletAccount = await myToken.createAssociatedTokenAccount( BANK_wallet.publicKey );


// transaction 
var transaction = new web3.Transaction()
      .add(
        splToken.Token.createTransferInstruction(
          splToken.TOKEN_PROGRAM_ID,
          B_walletAccount.address,
          A_walletAccount.address,
          BANK_wallet.publicKey,
          [],
          0
        )
      );

// signature 
var signature = await web3.sendAndConfirmTransaction() ....

But I got an error on:

// B account(from)
  const B_walletAccount = await myToken.createAssociatedTokenAccount( BANK_wallet.publicKey );
throw new TypeError('unexpected type, use Uint8Array');  
        ^  

TypeError: unexpected type, use Uint8Array

I tried by

const B_walletAccount = await myToken.createAssociatedTokenAccount([160,15,25, ...]);

But I got:

if (!allowOwnerOffCurve && !web3_js.PublicKey.isOnCurve(owner.toBuffer())) {  
                                                             ^  

TypeError: owner.toBuffer is not a function

When I use

getOrCreateAssociatedAccountInfo(B_wallet);

it's working but, Transaction is failed :

var transaction = new web3.Transaction()
      .add(
        splToken.Token.createTransferInstruction(
          splToken.TOKEN_PROGRAM_ID,
          B_walletAccount1.address,
          A_walletAccount.address,
          BANK_wallet.publicKey,
          [],
          2000000
        )
      );

// error : 
Transaction simulation failed: Error processing Instruction 0: custom program error: 0x4
    Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]
    Program log: Instruction: Transfer
    Program log: Error: owner does not match
*/

I need to have lot of address without SOL/lamports that I should transfer myToken between those addresses

TylerH
  • 20,799
  • 66
  • 75
  • 101
rokitman
  • 29
  • 4
  • It's looks like I need to find function : const mySecondWalletOwnedbyMe = createWalletFromOwner(BANK_Wallet); – rokitman Nov 22 '21 at 15:03

0 Answers0