With our platform, you can empower your smart contracts with the ability to facilitate seamless transactions. Take a look at this code snippet to see how you can enable the smooth transfer of assets between parties.
fn rent(env: Env, renter: Address, token: Address, duration: u128) {
transfer_from(
&env,
&payment_token,
&renter,
leaser,
price.try_into().unwrap(),
);
// Authorize leaser to transfer nft to renter
set_authorized(&env, &token, &leaser);
// Transfer nft to the renter
transfer_from(&env, &token, leaser, &renter, NFT_BALANCE);
// Set authorized to false so that user cannot
// transfer token unless delisted
set_unauthorized(&env, &token, &renter);
// Set all fields
let renting: Renting = Renting {
renter: renter.clone(),
rent_duration: duration,
rented_at: env.ledger().timestamp() as u128,
};
leaser_renter.renting = renting;
leaser_renter.state = LeaseState::Rented;
write_lease(&env, &token, &leaser_renter);
}
fn rent(env: Env, renter: Address, token: Address, duration: u128) {
transfer_from(
&env,
&payment_token,
&renter,
leaser,
price.try_into().unwrap(),
);
// Authorize leaser to transfer nft to renter
set_authorized(&env, &token, &leaser);
// Transfer nft to the renter
transfer_from(&env, &token, leaser, &renter, NFT_BALANCE);
// Set authorized to false so that user cannot
// transfer token unless delisted
set_unauthorized(&env, &token, &renter);
// Set all fields
let renting: Renting = Renting {
renter: renter.clone(),
rent_duration: duration,
rented_at: env.ledger().timestamp() as u128,
};
leaser_renter.renting = renting;
leaser_renter.state = LeaseState::Rented;
write_lease(&env, &token, &leaser_renter);
}