Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token transaction do not return any event #33

Closed
FrancescoGrazioso opened this issue Dec 23, 2021 · 13 comments
Closed

Token transaction do not return any event #33

FrancescoGrazioso opened this issue Dec 23, 2021 · 13 comments

Comments

@FrancescoGrazioso
Copy link

Using React, i'm trying to execute a token transfert using Hedera Token Service.
When i send the transaction to HashConnect the wallet prompts me to approve the transaction, but after that nothing happens.
Here's my code:

`export async function buyRTTToken(token, trsuaryAccountId,reciverAccountId) {
const client = hederaClient();
let transaction : TransferTransaction = await new TransferTransaction();
transaction.addTokenTransfer(token.tokenId, trsuaryAccountId, -10);
transaction.addTokenTransfer(token.tokenId, reciverAccountId, 10);
transaction.freezeWith(client);

await sendTransaction(transaction, reciverAccountId);

}`

`export async function sendTransaction(tx: Transaction, signignAccount: string) {
let transactionBytes: Uint8Array = tx.toBytes();

const transaction: MessageTypes.Transaction = {
    topic: saveData.topic,
    byteArray: transactionBytes,
    metadata: {
        accountToSign: signignAccount,
        returnTransaction: false
    }
}

await hashconnect.sendTransaction(saveData.topic, transaction)

hashconnect.transactionResponseEvent.once((data) => {
    console.log("transaction response", data)
})

}`

The following code aims to let the reciving user to sign the transaction and to pay for the fees of tranfer, since he is requesting token from the tresuary account

@teacoat
Copy link
Contributor

teacoat commented Dec 23, 2021

@FrancescoGrazioso Could you provide a screenshot of the console after clicking "Approve" in the demo wallet? It should display "SUCCESS" after a few moments, or throw an error if execution failed.

@teacoat
Copy link
Contributor

teacoat commented Dec 23, 2021

Or - this could be happening because the token you are trying to transfer is not associated to the demo account

@FrancescoGrazioso
Copy link
Author

The transaction to associate the token to the wallet account has the same problem, i'll attach the console on the approving transaction.
The problem is the same, i got no response from the event handler and the console/wallet do not display any "SUCCESS" message.

The following is the code that i'm using to approve the transaction

`
export async function associateTokenWithAccount(token, accountId) {
const client = hederaClient();
let transaction = await new TokenAssociateTransaction();
transaction.setAccountId(accountId);
transaction.setTokenIds([token.tokenId]);
transaction.freezeWith(client);

await sendTransaction(transaction, accountId);

}
`

`
export async function sendTransaction(tx: Transaction, signignAccount: string) {
let transactionBytes: Uint8Array = tx.toBytes();

const transaction: MessageTypes.Transaction = {
    topic: saveData.topic,
    byteArray: transactionBytes,
    metadata: {
        accountToSign: signignAccount,
        returnTransaction: false
    }
}

await hashconnect.sendTransaction(saveData.topic, transaction)

hashconnect.transactionResponseEvent.once((data) => {
    console.log("transaction response", data)
})

}
console on approving token

`

@teacoat
Copy link
Contributor

teacoat commented Dec 23, 2021

Yes so the demo wallet doesn't support the token associate function yet - it's still very much a WIP but I will prioritze adding token association.

Your events are going through fine, the wallet just doesn't have the UI to handle it yet!

@FrancescoGrazioso
Copy link
Author

Ok thanks, i'll close the issue when you'll release the new version of the wallet

@teacoat
Copy link
Contributor

teacoat commented Dec 23, 2021

Sounds good - I'll tag you when its ready :)

@FrancescoGrazioso FrancescoGrazioso changed the title Events are not handled correctly Token association is not supported by wallet Dec 23, 2021
@teacoat
Copy link
Contributor

teacoat commented Dec 23, 2021

@FrancescoGrazioso I've updated the demo wallet to support token associate/disassociate
image

@teacoat
Copy link
Contributor

teacoat commented Dec 23, 2021

Keep an eye on the console when using it - errors such as "TOKEN_ALREADY_ASSOCIATED" aren't handled by the demo wallet yet

@FrancescoGrazioso
Copy link
Author

Still nothing from the console, on every transaction i try.
I tried:

  • token association
  • token dissociation
  • token transfert

I'll attach some screen
dissociate
dissociate-code
dissociate-console

@FrancescoGrazioso FrancescoGrazioso changed the title Token association is not supported by wallet Token transaction do not return any event Dec 24, 2021
@teacoat
Copy link
Contributor

teacoat commented Dec 24, 2021

Hmmm that looks to me like it should work - can you reach out to me (pluto) on discord?

@teacoat
Copy link
Contributor

teacoat commented Dec 24, 2021

There was a bug in the demo where errors werent returning correctly - if you try now both the success and error transaction response events should fire - here is the log from the demo dapp, you can see both transaction responses there!

image

@FrancescoGrazioso
Copy link
Author

It is giving me now the following error
error_wallet

I reached you on discord

@FrancescoGrazioso
Copy link
Author

The problem was in the way i was freezing the transaction, with the new code it works!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants