Can you manually list a wallet address in a smart contract transaction? For example lets say I create a smart contract that allows any user to send Ada to a specific address by sending it to the scripts UTXO address is this possible?
1 Answer
You could hardcode public key hash of a receiver address and then validate if outgoing transaction is going towards address with same public key hash.
Here is an example how that would look like in plutus code:
...
data ContractInfo = ContractInfo
{
recvPkh :: !PubKeyHash
} deriving Show
contractInfo = ContractInfo
{
recvPkh = "3f7846896a48c59359746ff096d63606ceb82e65900d20a9fd2b8a93"
}
{-# INLINABLE mkValidator #-}
mkValidator :: ContractInfo -> () -> () -> ScriptContext -> Bool
mkValidator contractInfo@ContractInfo{..} _ _ ctx =
any outputToCorrectAddr txOuts
where
info :: TxInfo
info = scriptContextTxInfo ctx
txOuts :: [TxOut]
txOuts = txInfoOutputs info
outputToCorrectAddr :: TxOut -> Bool
outputToCorrectAddr txo = case toPubKeyHash $ txOutAddress txo of
Just pkh -> recvPkh == pkh
Nothing -> False
...