Skip to content

Instantly share code, notes, and snippets.

@clemsos
Last active December 20, 2024 11:14
Show Gist options
  • Select an option

  • Save clemsos/3ce1d700515da57f2564a9c19cec1295 to your computer and use it in GitHub Desktop.

Select an option

Save clemsos/3ce1d700515da57f2564a9c19cec1295 to your computer and use it in GitHub Desktop.

Revisions

  1. clemsos revised this gist Dec 20, 2024. 1 changed file with 31 additions and 3 deletions.
    34 changes: 31 additions & 3 deletions cctp-attestation.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,20 @@
    import { ethers } from 'hardhat'
    import { ethers } from 'ethers'

    const transactionHash =
    '0xc37329f7bfada70be0a695031b270741542d1dd477fc0a2e0f476d242b8ff508'

    // sepolia 11155111
    const srcChainRPC = 'https://sepolia.gateway.tenderly.co'

    // base sepolia 84532
    const destChainRPC = 'https://base-sepolia.gateway.tenderly.co'
    const messengerAddress = '0x7865fAfC2db2093669d92c0F33AeEF291086BEFD'

    async function main() {
    // decode message on origin chain
    const srcProvider = new ethers.JsonRpcProvider(srcChainRPC)
    const transactionReceipt =
    await ethers.provider.getTransactionReceipt(transactionHash)
    await srcProvider.getTransactionReceipt(transactionHash)
    const eventTopic = ethers.solidityPackedKeccak256(
    ['string'],
    ['MessageSent(bytes)']
    @@ -15,7 +24,26 @@ async function main() {
    const messageBytes = abiCoder.decode(['bytes'], log.data)[0]
    const messageHash = ethers.keccak256(messageBytes)

    console.log({ messageBytes, messageHash })
    // get attestation from Circle's servers
    // NB: url for testnets only
    const url = `https://iris-api-sandbox.circle.com/attestations/${messageHash}`
    const resp = await fetch(url)
    const { attestation, status } = await resp.json()
    console.log({ messageBytes, attestation, status })

    // receive attestation on dest server
    if (status === 'completed') {
    // get destination provider
    const destProvider = new ethers.JsonRpcProvider(destChainRPC)
    // TODO: parse signer
    // get contract
    const messenger = new ethers.Contract(
    messengerAddress,
    ['function receiveMessage(bytes,bytes)'],
    destProvider
    )
    await messenger.receiveMessage(messageBytes, attestation)
    }
    }

    main().then(() => console.log('ok'))
  2. clemsos revised this gist Dec 20, 2024. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions cctp-attestation.js
    Original file line number Diff line number Diff line change
    @@ -10,14 +10,12 @@ async function main() {
    ['string'],
    ['MessageSent(bytes)']
    )
    console.log(eventTopic)
    const log = transactionReceipt?.logs.find((l) => l.topics[0] === eventTopic)
    console.log(log)
    const abiCoder = ethers.AbiCoder.defaultAbiCoder()
    const messageBytes = abiCoder.decode(['bytes'], log.data)[0]
    const messageHash = ethers.keccak256(messageBytes)

    console.log({ messageHash })
    console.log({ messageBytes, messageHash })
    }

    main().then(() => console.log('ok'))
    main().then(() => console.log('ok'))
  3. clemsos created this gist Dec 20, 2024.
    23 changes: 23 additions & 0 deletions cctp-attestation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import { ethers } from 'hardhat'

    const transactionHash =
    '0xc37329f7bfada70be0a695031b270741542d1dd477fc0a2e0f476d242b8ff508'

    async function main() {
    const transactionReceipt =
    await ethers.provider.getTransactionReceipt(transactionHash)
    const eventTopic = ethers.solidityPackedKeccak256(
    ['string'],
    ['MessageSent(bytes)']
    )
    console.log(eventTopic)
    const log = transactionReceipt?.logs.find((l) => l.topics[0] === eventTopic)
    console.log(log)
    const abiCoder = ethers.AbiCoder.defaultAbiCoder()
    const messageBytes = abiCoder.decode(['bytes'], log.data)[0]
    const messageHash = ethers.keccak256(messageBytes)

    console.log({ messageHash })
    }

    main().then(() => console.log('ok'))