AdChain
Redefining Advertising: Flexibility Meets Fairness.
Created on 30th October 2024
•
AdChain
Redefining Advertising: Flexibility Meets Fairness.
The problem AdChain solves
In the digital marketing landscape, advertisers face significant challenges, including rigid ad placement structures, lack of transparency, and the complexities of dealing with intermediaries. These issues often lead to wasted budgets and inefficient campaigns, particularly for smaller businesses that struggle to access suitable ad spaces due to fixed pricing and minimum spend requirements. Additionally, ad fraud remains a pervasive problem, draining resources and undermining campaign effectiveness.
Your app addresses these challenges by creating an ads exchange that tokenizes ad inventory, transforming ad spaces into tradable assets on the blockchain. This innovation enhances transparency and allows real-time tracking of performance and inventory. By eliminating intermediaries, the platform connects advertisers directly with publishers, reducing costs and expediting transactions. The flexible pricing model and smart contracts align incentives, empowering businesses of all sizes to compete effectively in a secure and efficient advertising environment.
Challenges we ran into
While building the SubscriptionAdExchange contract, I faced a critical hurdle related to the ownership transfer of ad space tokens. The core issue arose during the implementation of the buyAdSpace function, where the ownership of an ERC721 token was to be transferred from the seller to the buyer upon successful payment.
The Problem:
When a buyer attempted to purchase an ad space token, the transaction would revert with an error message indicating that the token was not owned by the seller. This issue stemmed from not properly managing the state of the ad space and token ownership before executing the transfer. Specifically, it became evident that the order of operations in the function was not correctly validating the conditions for ownership transfer.
Debugging Steps Taken:
Code Review: I meticulously reviewed the logic in the buyAdSpace function to ensure that the ownership checks aligned with the current state of the contract. This involved going through each condition and validating their logical flow.
Event Logging: To gain insights into the variable states leading up to the error, I added event logs before key actions within the buyAdSpace function. By emitting events, I was able to track the values of critical variables (like the seller's address and token ownership) just before the ownership transfer, which illuminated the exact point of failure.
Testing with Remix: Utilizing the Remix IDE, I ran multiple test cases to simulate the buying process under various scenarios, including correct and incorrect states. This approach helped me reproduce the error consistently, allowing for a clearer understanding of the underlying issue.
Resolution:
After pinpointing that the issue was due to the order of operations—specifically that the ownership transfer was being executed before validating the buyer's payment—I refactored the code. The payment logic was adjusted to occur before the ownership transfer.
Tracks Applied (6)
🥇Buidl with PYUSD
PYUSD
🥈Buidl with PYUSD
PYUSD
🥉Buidl with PYUSD
PYUSD
Greater Good Award
PYUSD
QuickNode: Best Overall Project
QuickNode: Best use of QuickNode Functions
Technologies used
