1

I am trying to build a dApp where a user A sends a request to a user B mentioning a certain sum of ether that B can get.

If B accepts the offer, then B get the ether proposed by A.

When I'm logged in with B's address, I can't call the smart contract using A's address, which makes sense. However, I was wondering if there is something similar when logged with B's address as :

this.state.contract.methods.myFunction().send({ from: A_Address })

To sum up, I want that A sends a certain amount of Ether to B when B clicks on a button and the button appears only if A has allowed his consent. Is it possible ?

1 Answer 1

0

That's not directly possible without having A's private key. However there are other a bit more indirect ways:

1) A signs such a transaction in advance with his private key. He then sends the signed transaction to B (not via blockchain). If B wants to accept the transaction he broadcasts it to the blockchain. Or:

2) A middleman contract where A stores Ethers. When B calls some accept function in the contract the Ethers are sent to him.

4
  • Thank you a lot for your answer. I wasn't sure that 1) was possible. How can A send a transaction to B ? And how can B get the transaction ? Are there any specific functions to use ?
    – Julien
    Mar 10, 2020 at 17:04
  • Think of it as A writing a letter to the EVM instructing it to send Ethers to B. A then seals the letter in an envelope and gives the envelope to B. When B wants the Ethers he just has to deliver to whole envelope to EVM. B can't change the actual letter. In web3 there's a signTransaction function: web3js.readthedocs.io/en/v1.2.0/… Mar 11, 2020 at 5:07
  • Thank you. I've read about the signTransaction function but it requires the private key. Is there any way to sign without using the private key (I mean using it implicitly). I read a lot about it but most of people store their private key in plain text which, in my understanding, isn't a good idea.
    – Julien
    Mar 12, 2020 at 1:46
  • No you can't sign a transaction without a private key. That's the whole point of signing a transaction. But what I'm trying to say is that nobody else has to know A's private key - he himself signs the transaction and then sends it to B. Once the transaction has been signed there's no way to see the used private key. Mar 12, 2020 at 7:09

Your Answer

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

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