Last active
June 12, 2024 10:29
-
-
Save arcticfloyd1984/71616d1e8cf9c183272f299953b69238 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return (async () => { | |
const relay = new GelatoRelay(); | |
console.log("Web3Function invoked"); | |
const account = privateKeyToAccount('0x215816ad5bfd524e13dc8b6b2ed2674d8f8973f403ad80909111dfe3757bc9d6'); | |
const client = createWalletClient({ | |
account, | |
transport: http( | |
'https://opt-sepolia.g.alchemy.com/v2/hL0i6G6Rrp5GgKc_pa5JvezbgDLloVgz', // RPC URL of the network where the mint method is to be called | |
), | |
}); | |
const publicClient = createPublicClient({ | |
transport: http( | |
'https://arb-sepolia.g.alchemy.com/v2/MVGOoAkMUxl6jrN3qLaSt7Z9dDB7iLUU', // RPC URL of the network where burn event is to be fetched | |
), | |
}); | |
const { log } = context; | |
const { transactionHash } = log; | |
const receipt = await publicClient.getTransactionReceipt({ | |
hash: transactionHash, | |
}); | |
const { logs } = receipt; | |
let amount = BigInt(0); | |
for (const eventLog of logs) { | |
if ( | |
eventLog.topics[0] === | |
'0xcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5' // topic id of burn event | |
) { | |
const burnEvent = decodeEventLog({ | |
abi: ERC_20_TOKEN_ABI, | |
topics: eventLog.topics, | |
data: eventLog.data, | |
}); | |
const { args } = burnEvent; | |
amount = args.amount; | |
sender = args.sender; | |
} | |
} | |
//encode function data | |
const data = encodeFunctionData({ | |
abi: ERC_20_TOKEN_ABI, | |
functionName: 'mint', | |
args: [sender, amount], | |
}); | |
const relayRequest = { | |
user: account.address, | |
chainId: BigInt(11155420), | |
target: '0xCEA273008747DEE24A19Db8C949B62a100646295', // token address | |
data, | |
}; | |
const response = await relay.sponsoredCallERC2771( | |
relayRequest, | |
client, | |
'Yzrtu5XgInRoLytEbSjWNkwnPpZbyssXTdIZBlty2zU_', | |
); | |
return response.taskId; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment