I am using the solana candy-machine for minting the nft.
When i call smart contract function in javascript
import * as anchor from "@project-serum/anchor";
let program = new anchor.Program(idl, programId, provider);
let result = await program.rpc.someFunc(); //here is the smart contract function
browser will show pop up for you to approve the transaction. is There any way to know if user click cancel or approve?
In ethereum, it has something like below:
.on("transactionHash", function(hash) {
…
})
.on("error", function(error, receipt) {
…
});
is it possible to do it in candy machine? I want to do something after user click approved in transaction
Yes you can achieve something similar, however this would not be effective from the candy-machine directly.
There are probably multiple ways of doing it, but one that I found is using connection.getSignatureStatuses()
from Serum.
Code would look something like this, and it is similar to what you shared:
// Impor the connection dependencies
import * as anchor from '@project-serum/anchor';
// Loop using waiting for a positive status / or timeout
while (...) {
// Get the status using the transaction ID
const statusResponse = await connection.getSignatureStatuses([
txId,
]);
const status = statusResponse?.value[0];
if (status.err) {
// ...
}
}
Once you get the status of the transaction, which includes the user rejecting it, you can trigger the behavior in the frontend.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.