xdapp-book/src/technical/evm/nftLayer.md

64 lines
2.2 KiB
Markdown
Raw Normal View History

2022-09-21 10:13:51 -07:00
# NFT Bridge
2022-09-14 09:16:13 -07:00
2022-09-21 10:14:28 -07:00
This section will explain how to properly interact with the NFT Bridge Module in an EVM ecosystem.
2022-09-14 09:16:13 -07:00
2022-09-19 16:00:10 -07:00
## Configuring the interface
2022-09-14 09:16:13 -07:00
[Here](https://github.com/wormhole-foundation/wormhole/blob/main/ethereum/contracts/nft/interfaces/INFTBridge.sol) is the interface for applications to interact with Wormhole's NFT Bridge.
2022-09-14 09:16:13 -07:00
2022-09-19 18:04:13 -07:00
<!---
TODO
merge down the interface PR and link to actual file
-->
Instantiating the interface will depend on the contract address of your development ecosystem and blockchain.
2022-09-14 09:16:13 -07:00
2022-09-19 16:00:10 -07:00
Below is an example line of code to instantiate the interface for mainnet Ethereum:
2022-09-14 09:16:13 -07:00
2022-09-19 16:00:10 -07:00
```
address private wormhole_NFT_bridge_address = address(0x6FFd7EdE62328b3Af38FCD61461Bbfc52F5651fE);
INFTBridge NFT_bridge = INFTBridge(wormhole_nft_bridge_address);
```
2022-09-14 09:16:13 -07:00
2022-09-19 16:00:10 -07:00
## Transferring a NFT
2022-09-14 09:16:13 -07:00
2022-09-19 18:04:13 -07:00
The Wormhole NFT Bridge only supports tokens compliant with the ERC-721 interface, and functions by creating a 'wrapped NFT' with identical metadata. How this is implemented varies by ecosystem.
2022-09-14 09:16:13 -07:00
2022-09-22 13:26:14 -07:00
**Note**: Unlike tokens, there is no attestation required for bridging NFTs.
2022-09-14 09:16:13 -07:00
2022-09-19 16:00:10 -07:00
To transfer a NFT, there are three steps:
2022-09-14 09:16:13 -07:00
2022-09-19 16:00:10 -07:00
1. Initiate the NFT transfer
2022-09-19 18:04:13 -07:00
- This function call will return a `sequence` (uint64) that is used in the VAA retrieval step
2022-09-14 09:16:13 -07:00
2022-09-14 10:03:57 -07:00
```
2022-09-19 16:00:10 -07:00
transferNFT(tokenAddress, tokenID, recipientChain, recipient, nonce);
```
2022-09-14 10:03:57 -07:00
2022-09-19 18:04:13 -07:00
2. Retrieve the emitted VAA from the Guardian Network. (Usually done by a relayer)
2022-09-23 09:28:50 -07:00
- NFT Transfer VAAs are retrieved from the Guardian Network by the `emitterChainID`, `emitterAddress`, and `sequence`.
2022-09-19 18:04:13 -07:00
2022-09-22 13:55:34 -07:00
```js
2022-09-19 16:00:10 -07:00
const emitterAddr = getEmitterAddressEth(network.NFTBridgeAddress);
const seq = parseSequenceFromLogEth(tx, network.bridgeAddress);
const vaaURL = `${config.wormhole.restAddress}/v1/signed_vaa/${network.wormholeChainId}/${emitterAddr}/${seq}`;
let vaaBytes = await (await fetch(vaaURL)).json();
while (!vaaBytes.vaaBytes) {
console.log("VAA not found, retrying in 5s!");
await new Promise((r) => setTimeout(r, 5000)); //Timeout to let Guardiand pick up log and have VAA ready
vaaBytes = await (await fetch(vaaURL)).json();
}
```
2022-09-14 10:03:57 -07:00
2022-09-19 18:04:13 -07:00
3. Complete the NFT transfer by submitting the resultant VAA to the target chain.
2022-09-14 10:03:57 -07:00
2022-09-19 16:00:10 -07:00
```
completeTransfer(VAA);
```
2022-09-14 10:03:57 -07:00
2022-09-19 18:04:13 -07:00
<!---
TODO
2022-09-14 10:03:57 -07:00
2022-09-26 18:19:24 -07:00
additional use cases, most specifically how to grab the origin address of the wrapped NFT
2022-09-19 18:04:13 -07:00
-->