Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/examples/trusted-gateway-token/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@
"typescript": "^4.3.5"
},
"dependencies": {
"@chainlink/ethers-ccip-read-provider": "0.2.2",
"@types/node-fetch": "^2.5.12",
"dotenv": "^10.0.0",
"ethers": "^5.4.4",
"ethers": "^5.6.9",
"jayson": "^3.6.4",
"node-fetch": "^2.6.1"
}
Expand Down
45 changes: 37 additions & 8 deletions packages/examples/trusted-gateway-token/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { providers, Transaction } from 'ethers';

const ethers = require('ethers');
const ccipread = require('@chainlink/ethers-ccip-read-provider');
const fs = require('fs');

require('dotenv').config({ path: '../.env' });
Expand All @@ -14,26 +15,54 @@ const abi = JSON.parse(
const RECIPIENT = '0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199';
const { TOKEN_ADDRESS, PROVIDER_URL, SENDER_ACCOUNT_INDEX } = process.env;

const provider = new ccipread.CCIPReadProvider(
new ethers.providers.JsonRpcProvider(PROVIDER_URL)
);
class MyCustomProvider extends providers.JsonRpcProvider {
async ccipReadFetch(
tx: Transaction,
calldata: string,
urls: Array<string>
): Promise<null | string> {
urls = urls.filter((u: any) => isSafeUrl(u));
return super.ccipReadFetch(tx, calldata, urls);
}
}

function isSafeUrl(url: string): boolean {
console.log(`Allowing ${url}`);
return true;
}

const provider = new MyCustomProvider(PROVIDER_URL);
const signer = provider.getSigner(parseInt(SENDER_ACCOUNT_INDEX as string));
const erc20 = new ethers.Contract(TOKEN_ADDRESS, abi, signer);

async function main() {
const amount = 1;
const sender = await signer.getAddress();

console.log(`SENDER ${sender} balance ${await erc20.balanceOf(sender)}`);
console.log(`CCIP enabled: ${!provider.disableCcipRead}`);

console.log(
`SENDER ${sender} balance ${await erc20.balanceOf(sender, {
ccipReadEnabled: true,
})}`
);
console.log(
`RECIPIENT ${RECIPIENT} balance ${await erc20.balanceOf(RECIPIENT)}`
`RECIPIENT ${RECIPIENT} balance ${await erc20.balanceOf(RECIPIENT, {
ccipReadEnabled: true,
})}`
);
console.log(`TRANSFER ${amount} from ${sender} to ${RECIPIENT}`);
const tx = await erc20.transfer(RECIPIENT, amount);
await tx.wait();
console.log(`SENDER ${sender} balance ${await erc20.balanceOf(sender)}`);
console.log(
`RECIPIENT ${RECIPIENT} balance ${await erc20.balanceOf(RECIPIENT)}`
`SENDER ${sender} balance ${await erc20.balanceOf(sender, {
ccipReadEnabled: true,
})}`
);
console.log(
`RECIPIENT ${RECIPIENT} balance ${await erc20.balanceOf(RECIPIENT, {
ccipReadEnabled: true,
})}`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"chai": "^4.2.0",
"dotenv": "^10.0.0",
"ethereum-waffle": "^3.0.0",
"ethers": "^5.0.0",
"ethers": "^5.6.9",
"hardhat": "^2.7.1"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/trusted-gateway-token/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
"typescript": "^4.3.5"
},
"dependencies": {
"@chainlink/ccip-read-server": "0.2.1",
"@chainlink/ccip-read-server": "^0.2.1",
"dotenv": "^10.0.0",
"ethers": "^5.4.4",
"ethers": "^5.6.9",
"ts-node": "^10.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"cors": "^2.8.5",
"ethers": "^5.3.1",
"ethers": "^5.6.9",
"express": "^4.17.1"
}
}