---
# System prepended metadata

title: Untitled

---

```
const ethers = require("ethers")
require('dotenv').config();
const infura_url = process.env.INFURA_URL
const privateKey = process.env.EPNS_ADMIN_PRIVATE_KEY

const provider = new ethers.providers.JsonRpcProvider(infura_url);
const wallet = new ethers.Wallet(privateKey, provider)

const oldContractAddress = "0xc882dA9660d29c084345083922F8a9292E58787D"
const oldContractABI = require("./oldContractABI.json")
const oldContract = new ethers.Contract(oldContractAddress, oldContractABI, provider)

const newContractAddress = "0x77589b22d37C94473c17128beeb6bc3DaB58c09a"
const newContractABI = require("./newContractABI.json")
const newContract = new ethers.Contract(newContractAddress, newContractABI, provider)
const signingContract = newContract.connect(wallet)

//get channel detail from old contract
const getChannelCreatedEvents = async () => {
    return new Promise((resolve, reject) => {
        const filter = oldContract.filters.AddChannel();
        oldContract.queryFilter(filter, 10365222, 11175203).then(response => {
            // console.log(response)
            resolve(response)
        })
    })

}

//migrate channel from old contract to new contract
const migrateChannel = async () => {
    let channelArrayList = []
    let channelTypeArrayList = []
    let channelIdentityArrayList = []
    let daiArray = []
    return new Promise((resolve, reject) => {
        getChannelCreatedEvents().then(async res => {
            
            for (let i = 0; i < res.length; i++) {

                channelArrayList.push(res[i].args.channel)
                channelTypeArrayList.push(res[i].args.channelType)
                channelIdentityArrayList.push(res[i].args.identity)
                daiArray.push((50 * Math.pow(10, 18)).toString())


            }
            console.log(channelArrayList)
            // CALLING CONTRACT FUNCTION
            const txPromise = signingContract.migrateChannelData(0, res.length, channelArrayList, channelTypeArrayList, channelIdentityArrayList, daiArray);
            txPromise
                .then(async function (tx) {
                    console.info('Transaction sent: %o', tx);
                    await tx.wait(5);
                    resolve(tx);
                })
                .catch((err) => {
                    console.error('Unable to complete transaction, error: %o', err);

                    reject(`Unable to complete transaction, error: ${err}`);
                });

        })

    })
}

migrateChannel()
```