bridgeErc721
ERC-721 (KIP-17) 토큰을 다른네트워크로 브릿지합니다.
const ethers = require('ethers');
const network = "ETHEREUM"
const fromAddress = "0x1400594A07925C7110B9D22791f220Ee924C0513"
const toNetwork = "KLAYTN"
const contract_address = "0xED5AF388653567Af2F388E6224dC7C4b3241C544"
const token_id = "3258"
const name = "wAzuki"
const symbol = "wAk"
const rpcUrl = "https://ethereum.publicnode.com"
const toNetworkHex = "0X4B4C4159544E"
const transferContractAddress = "0x9a1c0ef3989f944e692232d491fe5395927be9bd"
const bridgeSetupContractAddress = "0x3cf93d43251324c527346abf3e0559f4c7a713d1"
const bridgeErc721Async = async(network, fromAddress, toNetwork, contract_address, token_id, name, symbol) => {
try {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const type = (await getNodeHomeAsync(network, toNetwork, contract_address "nft")).type;
let functionData;
let toContractAddress;
if (type === "setup") {
const bridgeSetupContract = new ethers.Contract(
bridgeSetupContractAddress,
abiBridgeSetup,
provider
);
functionData = bridgeSetupContract.interface.encodeFunctionData('setupFromERC721', [
toNetworkHex, name, symbol, fromAddress, contract_address, token_id
]);
toContractAddress = bridgeSetupContractAddress;
} else {
const nftTransferContract = new ethers.Contract(
transferContractAddress,
abiTransfer,
provider
);
functionData = transferContract.interface.encodeFunctionData('moveFromERC721', [
toNetworkHex, contract_address, token_id
]);
toContractAddress = transferContractAddress;
}
const bridgeFee = (await getNetworkFeeAsync(network, toNetwork, type)).networkFee;
const gasPrice = await provider.getGasPrice();
const gasLimit = await provider.estimateGas({
from: ownerAddress,
to: toContractAddress,
value: bridgeFee,
data: functionData
});
let transactionDetails;
if (network === "bnb") {
transactionDetails = {
from: ownerAddress,
to: toContractAddress,
gas: gasLimit.toHexString(),
value: bridgeFee.toHexString(),
data: functionData
};
} else {
transactionDetails = {
from: ownerAddress,
to: toContractAddress,
gasLimit: gasLimit.toHexString(),
value: bridgeFee.toHexString(),
data: functionData,
maxPriorityFeePerGas : maxPriorityFeePerGas.toHexString(),
maxFeePerGas :gasPrice.toHexString()
};
}
return {
result: "OK",
transaction : transactionDetails
}
} catch (e) {
return {
result: "FAIL",
error: e.message
};
}
}
Last updated