Skip to content

Instantly share code, notes, and snippets.

@calpa
Last active June 3, 2023 05:56
Show Gist options
  • Save calpa/81c872c95173a18425cce33a2758c1f3 to your computer and use it in GitHub Desktop.
Save calpa/81c872c95173a18425cce33a2758c1f3 to your computer and use it in GitHub Desktop.
Check Self Yuliverse Claim Transaction
import { axios } from "@pipedream/platform";
import moment from 'moment';
export default defineComponent({
props: {
address: {
type: "string",
label: "Address",
default: "",
},
contract: {
type: "string",
label: "Contract",
default: "",
},
apiKeyToken: {
type: "string",
label: "API Key Token",
secret: true,
},
},
async run({ steps, $ }) {
const url = `https://api.bscscan.com/api?module=account&action=txlist&address=${this.address}&startblock=0&endblock=99999999&sort=asc&apikey=${this.apiKeyToken}`;
const response = await axios(this, {
method: "GET",
url: url,
});
const claimMethodSignature = "0x5eddd157";
const transactions = response.result.reverse();
// Get today's date
const today = moment();
for (const transaction of transactions) {
console.log(transaction);
// Get the transaction's timestamp
const timestamp = parseInt(transaction.timeStamp) * 1000;
// Convert the timestamp to a Moment.js object
const transactionDate = moment(timestamp);
// Compare if the transaction's date is today
if (transactionDate.isSame(today, 'day')) {
if (
transaction.to.toLowerCase() === this.contract.toLowerCase() &&
transaction.input.startsWith(claimMethodSignature)
) {
console.log(transaction);
$.flow.exit('Claimed');
}
}
}
return null; // No transaction found today, return null
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment