forked from LayerZero-Labs/endpoint-v1-solidity-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonftSend.js
33 lines (28 loc) · 1.39 KB
/
onftSend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const CHAIN_ID = require("../constants/chainIds.json")
module.exports = async function (taskArgs, hre) {
const signers = await ethers.getSigners()
const owner = signers[0]
const toAddress = owner.address
const tokenId = taskArgs.tokenId
// get remote chain id
const remoteChainId = CHAIN_ID[taskArgs.targetNetwork]
// get local contract
const onft = await ethers.getContract(taskArgs.contract)
// quote fee with default adapterParams
const adapterParams = ethers.utils.solidityPack(["uint16", "uint256"], [1, 200000]) // default adapterParams example
const fees = await onft.estimateSendFee(remoteChainId, toAddress, tokenId, false, adapterParams)
const nativeFee = fees[0]
console.log(`native fees (wei): ${nativeFee}`)
const tx = await onft.sendFrom(
owner.address, // 'from' address to send tokens
remoteChainId, // remote LayerZero chainId
toAddress, // 'to' address to send tokens
tokenId, // tokenId to send
owner.address, // refund address (if too much message fee is sent, it gets refunded)
ethers.constants.AddressZero, // address(0x0) if not paying in ZRO (LayerZero Token)
adapterParams, // flexible bytes array to indicate messaging adapter services
{ value: nativeFee.mul(5).div(4) }
)
console.log(`✅ [${hre.network.name}] sendFrom tx: ${tx.hash}`)
await tx.wait()
}