<p>You can do this with multisignatures (no smart contract required). Because of how flexible the (e)UTXO model is, it's possible to construct a transaction that spends from two different addresses, as long as both of the parties involved sign the transaction with their signing key. Imagine party A has 10 ADA, and party B has 1 native asset lets call it XDA, the aim is for party A to buy one XDA from party B in exchange for 10 ADA.</p>
<p>Party A: build Tx with their own utxos as input, and as output they set 10 ADA to party B, and then they add another input using the UTXO of party B, and as output they set 1 XDA to party A address. So you get a transaction like so:</p>
<pre><code>INPUTS
  partyAUtxo [containing ADA]
  partyBUtxo [containing XDA]

OUTPUTS
  10 ADA -&gt; partyBAddress
  1  XDA -&gt; partyAAddress
</code></pre>
<p>party A now signs this transaction and sends the serialized signed transaction to party B. Now party B verifies that the trade seems fair (simply checking the price is fair or whatever), signs it with their keys and submits the transaction to the blockchain.</p>
<p>This constructs an atomic swap in a SINGLE TX, which would require two transactions if using a smart contract (lock, and unlock).</p>
<p>I would include the code here, but it'd require quite a bit of code to give you a working demo so I can just guide you to checkout <a href="https://github.com/Emurgo/cardano-serialization-lib" rel="nofollow noreferrer">cardano-serialization-lib</a>, and <a href="https://github.com/Berry-Pool/nami-wallet" rel="nofollow noreferrer">Nami wallet</a> - these two libraries/APIs provide all of the above functionality in terms of getting UTXOs, constructing transactions from UTXOs with custom outputs, building/serializing the transaction, signing it with a wallet, and submitting a transaction to Blockfrost. If I get a simple demonstration of this in action soon I will update here.</p>

CC BY-SA 4.0
2021-11-26T12:53:12.977Z
2021-11-26T12:53:12.977Z
Thom
<p>There are no such example that I know of, but you can create one, by monitoring an incoming address for new transaction and trigger a faucet server, something like <a href="https://github.com/input-output-hk/cardano-faucet" rel="nofollow noreferrer"><code>cardano-faucet</code></a>.</p>
<p>If you are looking for a smart contract and not a federated solution, you are probably thinking about a token swap.</p>
<p>In the Plutus Pioneer Program, the <a href="https://www.youtube.com/watch?v=CPfcyDaDtt8" rel="nofollow noreferrer">Lecture #10</a> explains an uniswap contract, which might be helpful to you.</p>

CC BY-SA 4.0
2021-11-25T23:07:01.923Z
2021-11-25T23:07:01.923Z
Marek Mahut - StakeNuts
<p>I wondering if is there any script o smart contract example which when i send X ada to a wallet after i receive a native token</p>

<smart-contract><ada>
Is there any script or smart contract which send tokens?
# Is there any script or smart contract which send tokens?

(Asked by: username_0 on 2021-11-25)

I wondering if is there any script o smart contract example which when i send X ada to a wallet after i receive a native token

**Tags:** smart-contract, ada

---

## 2 answers

### Answer by username_1 on 2021-11-26. Score: 2

You can do this with multisignatures (no smart contract required). Because of how flexible the (e)UTXO model is, it's possible to construct a transaction that spends from two different addresses, as long as both of the parties involved sign the transaction with their signing key. Imagine party A has 10 ADA, and party B has 1 native asset lets call it XDA, the aim is for party A to buy one XDA from party B in exchange for 10 ADA.
Party A: build Tx with their own utxos as input, and as output they set 10 ADA to party B, and then they add another input using the UTXO of party B, and as output they set 1 XDA to party A address. So you get a transaction like so:
INPUTS
  partyAUtxo [containing ADA]
  partyBUtxo [containing XDA]

OUTPUTS
  10 ADA -> partyBAddress
  1  XDA -> partyAAddress

party A now signs this transaction and sends the serialized signed transaction to party B. Now party B verifies that the trade seems fair (simply checking the price is fair or whatever), signs it with their keys and submits the transaction to the blockchain.
This constructs an atomic swap in a SINGLE TX, which would require two transactions if using a smart contract (lock, and unlock).
I would include the code here, but it'd require quite a bit of code to give you a working demo so I can just guide you to checkout cardano-serialization-lib, and Nami wallet - these two libraries/APIs provide all of the above functionality in terms of getting UTXOs, constructing transactions from UTXOs with custom outputs, building/serializing the transaction, signing it with a wallet, and submitting a transaction to Blockfrost. If I get a simple demonstration of this in action soon I will update here.


---

### Answer by username_2 on 2021-11-25. Score: 0

There are no such example that I know of, but you can create one, by monitoring an incoming address for new transaction and trigger a faucet server, something like [`cardano-faucet`](https://github.com/input-output-hk/cardano-faucet).

If you are looking for a smart contract and not a federated solution, you are probably thinking about a token swap.

In the Plutus Pioneer Program, the [Lecture #10](https://www.youtube.com/watch?v=CPfcyDaDtt8) explains an uniswap contract, which might be helpful to you.


---

