Skip to content

Commit

Permalink
improve value tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jun 30, 2023
1 parent cc33fc5 commit d370ff3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions messaging/value/tasks/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,33 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const zetaTokenAddress = getAddress("zetaToken", hre.network.name as any);
const zetaFactory = await hre.ethers.getContractFactory("ZetaEth");
const zetaToken = zetaFactory.attach(zetaTokenAddress);
await zetaToken.approve(args.contract, parseEther(args.amount));

const destination = hre.config.networks[args.destination]?.chainId;
if (destination === undefined) {
throw new Error(`${args.destination} is not a valid destination chain`);
}

const recipient = args.address || signer.address;
const amount = parseEther(args.amount);

await (await zetaToken.approve(args.contract, amount)).wait();

const tx = await contract
.connect(signer)
.send(args.destination, args.address, parseEther(args.amount));
.send(destination, recipient, amount);

const receipt = await tx.wait();
console.log(`✅ "sendHelloWorld" transaction has been broadcasted to ${hre.network.name}
console.log(`✅ Transaction has been broadcasted to ${hre.network.name}
📝 Transaction hash: ${receipt.transactionHash}
Please, refer to ZetaChain's explorer for updates on the progress of the cross-chain transaction.
🌍 Explorer: https://athens3.explorer.zetachain.com/address/${args.contract}
`);
`);
};

task("send", "Sends a message from one chain to another.", main)
.addParam("contract", "Contract address")
.addParam("address")
.addParam("amount", "Token amount to send")
.addParam("destination", "Destination chain ID (integer)");
.addOptionalParam("address", "Recipient address")
.addParam("amount", "Amount of ZETA tokens to send")
.addParam("destination", "Destination chain");

0 comments on commit d370ff3

Please sign in to comment.