#Sending an Asset to a NFD Vault that isn't opted into the Asset

20 messages · Page 1 of 1 (latest)

midnight ferry
#

Is it possible to send an assetTransfer to an address (like an NFD Vault) that hasn't opted into the asset yet?

I attempted to send an assetTransfer to a vault address that hasn't opted into the asset yet.
I then experimented with sending 0.1 ALGO to the vault address, thinking it might trigger the opt-in process, but it didn't work.

Any thoughts? Thanks!

#

Oh wait just thinking about it as if it was a normal interaction sending to an NFD -

If I send it to their nfdomain (I extracted the owner address) and it's not opted in will it automatically be sent to the nfdvault (nfdaccount address)?

plain flax
#

You have to use the NFD Send feature to send an ASA to a vault so that the necessary txn can be prepared

#

The vault can't opt in on its own without being called properly

midnight ferry
#

Sorry for slow response just back working on this now!

The links were very helpful - I am encountering an issue when im trying to import 'TransactionsArray' and 'encodeNFDTransactionsArray' from use-wallet modules

import { TransactionsArray, encodeNFDTransactionsArray } from '@txnlab/use-wallet'

I have npm installed use-wallet i also have use-wallet-react as I was using that before this.

I don't need to instantiate them locally do I as in the example it was easily imported.

and here is my code trying to sendToVault:

#
      console.log('Resolved Address:', resolvedAddress)

      const signer = await wallet.transactionSigner // Get the signer

      // If the address is resolved to vault (from NFD_NAME)
      if (resolvedAddress === receiverAddress) {
        console.log('Sending to vault...')

        // Using the sendToVault function to handle the vault interaction
        const response = await sendToVault(receiverAddress, {
          sender: activeAddress,
          assets: [ORA_ASSET_ID], 
          amount: Number(amountInMicroORA), // Convert to number
          optInOnly: false,
        })

        console.log('Vault Response:', response)
        if (typeof response.data !== 'string') {
          throw new Error('Failed to fetch transactions from vault')
        }

        const transactionsArray = JSON.parse(response.data) as TransactionsArray

        const signedTransactions = await signTransactions(encodeNFDTransactionsArray(transactionsArray))

        const { id } = await wallet.sendTransactions(signedTransactions)

        const notificationMessage = `Transaction Sent: <a href="https://lora.algokit.io/mainnet/transaction/${id}" target="_blank" rel="noopener noreferrer" style="font-weight: bold; text-decoration: underline; cursor: pointer;">Explore more</a>`

        triggerNotification(notificationMessage, 'success')```

and just to be sure here are my imports where the red squiggle lines are preventing the frontend from loading properly:

```import { TransactionsArray, encodeNFDTransactionsArray, useWallet } from '@txnlab/use-wallet'```
#

I also have my helper sendToVault from api file set up and npm install axios @txnlab/use-wallet done

midnight ferry
valid gull
#

@modest mirage can help if still having issues w/ the handling of nfd responses, etc.
Not sure if the code example needs updated or not.

modest mirage
#

Oh yeah those code examples will need to be updated

#

Here's how you can implement this in your project:

type TransactionsArray = ['u' | 's', string][]

function encodeNFDTransactionsArray(txnsArray: TransactionsArray): Uint8Array[] {
  return txnsArray.map(([_, txn]) => base64ToByteArray(txn))
}

function base64ToByteArray(base64Str: string): Uint8Array {
  const binaryStr = atob(base64Str)
  const byteArray = new Uint8Array(binaryStr.length)
  
  for (let i = 0; i < binaryStr.length; i++) {
    byteArray[i] = binaryStr.charCodeAt(i)
  }
  
  return byteArray
}
#

FYI I'm working on a NFD JS SDK library that will be available very soon

#

The initial v0.x release will cover forward/reverse lookups, minting, and some basic management

#

It'll have a bunch of utility functions as well and I'll make sure those missing use-wallet v2 exports are in there!

midnight ferry
#

Hey @modest mirage Thank you so much for the reply and the code!

I have another quick question so im using import { useWallet } from '@txnlab/use-wallet-react' v4

I can't find any send txn properties. I know send Transaction is in @txnlab/use-wallet but then there is only baseWallet suggestion when i try to import use-wallet. Plus it would be better to just stay in the use-wallet-react v4!

I also tried to look inside the algorandClient to be able to send a Transaction but then I have to fill out the parameters. Which I can't do as I have the txn all ready to just be sent to the network at that point:


        const signedTransactions = await signTransactions(encodeNFDTransactionsArray(transactionsArray))

// need to implement sending the txn to the network```
arctic trailBOT
#

Gave +1 Rep to @modest mirage (current: #35 - 5)

midnight ferry
#

Would i use something like the transaction composer to sort of group that one transaction and send it to the network? I'll give that a go in the mean time

midnight ferry
#

I got this to work!

        const transactionsArray = JSON.parse(response.data) as TransactionsArray

        // Encode the transactions into a format that can be signed
        const encodedTxns = encodeNFDTransactionsArray(transactionsArray)

        // Sign the transactions
        const signedTransactions = await signTransactions(encodedTxns)

        // Remove null values as it does not accept them only UInt
        const validSignedTxns = signedTransactions.filter((txn) => txn !== null) as Uint8Array[]

        // Send the transactions to the network
        const id = await algorand.client.algod.sendRawTransaction(validSignedTxns).do()```

it was a bit messy with the null value it wouldn't let it go through so i had to filter them out and then send the transaction. Tested it tho and the ORA went to my vault succesfully if I was not opted in! 🥳
modest mirage
#

Starting in use-wallet v3, sending transactions to the network is handled by algod (or ATC if that's what you're using). The sendTransactions function in v2 was just calling sendRawTransaction anyway.