0

Let's say I'm Wallet A, another user is Wallet B and I also have a smart contract.

With the smart contract I will build a transaction to send as Wallet B. So normally, for the transaction to be sent, Wallet B needs to manually sign it with his private key.

Is it possible to notify him on-chain for this transaction? Like, after I build and submit a transaction, if he is using his wallet at that time (for example he is connected to x dApp), is it possible that he gets notified through his wallet for that transaction?

If not, what are some possible ways to notify him on-chain?

2
  • It's not very clear to me what you mean by on-chain notification or the flow that you are trying to solve here. Could you try to rephrase the question / give more details? Commented Oct 21 at 19:31
  • To "notify" Wallet B, you could either send some data directly to Wallet B, or you could create an event in your smart contract that is emitted when the transaction is ready to be signed. Wallet B would just need to be watching out for these smart contract events.
    – Rohan Nero
    Commented Oct 21 at 19:47

2 Answers 2

1

You cannot notify another wallet as Ethereum does not have a built-in notification system like that. What smart contracts can do, is emit events, which are basically logs written to the blockchain. If connected to a dApp or any application that is listening for these events, you can use a websocket / JSON-RPC subscription. When the event is detected, the dApp can notify user.

basic example for the event

event EventFromWalletAToWalletB(address sender, address receiver, uint256 amount);
function requestTransaction(address receiver, uint256 amount) public {
    // ... some logic
    emit EventFromWalletAToWalletB(msg.sender, receiver, amount);
}

basic example in a dApp

const contract = new web3.eth.Contract(abi, contractAddress);

contract.events.EventFromWalletAToWalletB({})
    .on('data', (event) => {
        console.log('Custom event data:', event);
    })
    .on('error', console.error);

Obviously you need to adapt this concept to the contract and dApp your are building.

0

Thank you for the answers. Let me rephrase the question:

Metamask and other wallets have a "suggest transactions" permission that give to dApps whenever the wallet connects to them.

But is there another way to suggest a transaction to a wallet? As Wallet A or a smart contract owner, is it possible to suggest a transaction for Wallet B to approve or reject?

If no, how does this permission on the wallets work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.