watcher-ts/packages/erc20-watcher/test/tasks/token-transfer-from.ts
Ashwin Phatak 4f8f1d8cd7
Update code for log_cids change in vdb core (#243)
* Remove fields no longer present in schema.

* Refactor code to work with log_cids change in eth-server.

* Refactor process event to save events from logs.

* Use constants for erc20 event names.

* Implement watch blocks in erc20-watcher similar to uni-watcher.

* Moved common methods to util.

* Implement eventsInRange query in erc20-watcher.

* Filter unknown event in database query.

* Change dependencies version to be same in all packages.

Co-authored-by: nabarun <nabarun@deepstacksoft.com>
2021-09-21 16:43:55 +05:30

38 lines
1.4 KiB
TypeScript

//
// Copyright 2021 Vulcanize, Inc.
//
import { task, types } from 'hardhat/config';
import '@nomiclabs/hardhat-ethers';
import { ContractTransaction } from 'ethers';
task('token-transfer-from', 'Send tokens as spender')
.addParam('token', 'Token contract address', undefined, types.string)
.addParam('spenderKey', 'Spender private key', undefined, types.string)
.addParam('to', 'Transfer recipient address', undefined, types.string)
.addParam('amount', 'Token amount to transfer', undefined, types.int)
.setAction(async (args, hre) => {
const { token: tokenAddress, to, amount, spenderKey } = args;
await hre.run('compile');
const [owner] = await hre.ethers.getSigners();
const wallet = new hre.ethers.Wallet(spenderKey, hre.ethers.provider);
const Token = await hre.ethers.getContractFactory('GLDToken');
let token = Token.attach(tokenAddress);
token = token.connect(wallet);
const transaction: ContractTransaction = await token.transferFrom(owner.address, to, amount);
const receipt = await transaction.wait();
if (receipt.events) {
const TransferEvent = receipt.events.find(el => el.event === 'Transfer');
if (TransferEvent && TransferEvent.args) {
console.log('Transfer Event');
console.log('from:', TransferEvent.args.from.toString());
console.log('to:', TransferEvent.args.to.toString());
console.log('value:', TransferEvent.args.value.toString());
}
}
});