0

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

New contributor
Eros Nahuel Puca is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
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.

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 explains an uniswap contract, which might be helpful to you.

0

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.

Your Answer

Eros Nahuel Puca is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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