async associateToAccount({ privateKey, tokenIds, accountId }) {
		const client = this.#client

		const transaction = await new TokenAssociateTransaction()
			.setAccountId(accountId)
			.setTokenIds(tokenIds)
			.setMaxTransactionFee(new Hbar(100, HbarUnit.Hbar))
			.freezeWith(client)

		const accountPrivateKey = PrivateKey.fromString(privateKey)
		const signTx = await transaction.sign(accountPrivateKey)
		const executeTx = await signTx.execute(client)

		// Wait to finish for consensus and catch if association has already happened
		try {
			await executeTx.getReceipt(client)
		} catch (_) {
			console.warn(
				`Account: ${accountId} already associated to token - ${tokenIds}`
			)
		}

		return executeTx
	}
// Before transferring token to other account association is require
Before transferring token to other account association is require
Before transferring token to other account association is require
async associateToAccount({ privateKey, tokenIds, accountId }) {
		const client = this.#client
		const transaction = await new TokenAssociateTransaction()
			.setAccountId(accountId)
			.setTokenIds(tokenIds)
			.setMaxTransactionFee(new Hbar(100, HbarUnit.Hbar))
			.freezeWith(client)
		const accountPrivateKey = PrivateKey.fromString(privateKey)
		const signTx = await transaction.sign(accountPrivateKey)
		const executeTx = await signTx.execute(client)
		try {
			await executeTx.getReceipt(client)
		} catch (_) {
			console.warn(
				`Account: ${accountId} already associated to token - ${tokenIds}`
			)
		}
		return executeTx
	}
async associateToAccount ( { privateKey , tokenIds , accountId } ) { const client = this . #client const transaction = await new TokenAssociateTransaction ( ) . setAccountId ( accountId ) . setTokenIds ( tokenIds ) . setMaxTransactionFee ( new Hbar ( 100 , HbarUnit . Hbar ) ) . freezeWith ( client ) const accountPrivateKey = PrivateKey . fromString ( privateKey ) const signTx = await transaction . sign ( accountPrivateKey ) const executeTx = await signTx . execute ( client ) try { await executeTx . getReceipt ( client ) } catch ( _ ) { console . warn ( ` ${ accountId } ${ tokenIds } ` ) } return executeTx }
Before transferring token to other account association is require
Before transferring token to other account association is require
// Wait to finish for consensus and catch if association has already happened