Reputation: 563
I want to call a function named "testFunction" which takes "claimDate" as a parameter. claimDate parameter comes from a server via api.
contract TestSmartContract {
testFunction(uint256 id, uint256 claimDate) public payable returns (uint) {
// I need a logic to verify if claimDate is coming from a valid source which will mean it is correct.
}
}
Upvotes: 1
Views: 543
Reputation: 238
In short, you can use signature verification to check if the data comes from the verified source.
The idea is that;
claimDate
from off-chain (ex. backend server).claimDate
together with the signature to the contract.claimDate
is really from the source.⚠️ Note that signing
claimDate
alone might not be enough. Because once the signature is created, it can be visible and reused by exploiters.
Read more: https://blog.chainsafe.io/how-to-verify-a-signed-message-in-solidity-6b3100277424
Upvotes: 3
Reputation: 294
You can use the wallet address to validate if the source is valid.
For example:
contract TestSmartContract {
address sourceAddress = "0x00...";
function testFunction(uint256 id, uint256 claimDate) public returns(uint) {
require(msg.sender == sourceAddress, "Not valid source");
//code to execute
}
}
Upvotes: 1