This sets the owner of the contract to the deployer and initializes interfaces for the Wormhole Core Bridge and Token Bridge.
```solidity
constructor(
string memory name_,
string memory symbol_,
address coreBridgeAddress,
address tokenBridgeAddress
) ERC20(name_, symbol_) {
owner = msg.sender;
core_bridge = IWormhole(coreBridgeAddress);
token_bridge = ITokenBridge(tokenBridgeAddress);
}
```
## RegisterApplicationContracts
It's typically a good idea to register and track the contracts from foreign chains that you're accepting VAAs from, as anyone could deploy a contract and generate a fake VAA that looks like a real VAA you'd want to accept.
```solidity
/**
Registers it's sibling applications on other chains as the only ones that can send this instance messages
*/
function registerApplicationContracts(uint16 chainId, bytes32 applicationAddr) public {
require(msg.sender == owner, "Only owner can register new chains!");
_applicationContracts[chainId] = applicationAddr;
}
```
## SubmitForeignPurchase
This takes in a bytes payload and calls the Wormhole Token Bridge to receive the bridged tokens, mint the corresponding amount of native token, and calls the Wormhole Token Bridge to send the newly minted tokens back to the user.
The `completeTransferWithPayload()` function of the token bridge takes one argument:
- encodedVm: The unverified and unparsed message that is generated by the Guardian Network
The `transferTokens()` function of the token bridge takes six arguments:
- Token: contract address of the token
- Amount: amount of tokens to transfer
- RecipientChain: ChainID of the target chain
- Recipient: address for target wallet
- ArbiterFee: amount of tokens the user is willing to pay as relayer fee
- Nonce: A number to uniquely identify this message, optionally used for batching when multiple messages are generated by the same transaction. See [here](../../technical/evm/coreLayer.md) for more details.
```solidity
/**
Takes inventory of the foreign currency
Mints tokens to self
Transfers tokens with Payload 1 to Receipient on Foreign chain
*/
function submitForeignPurchase(bytes memory encodedVm) public returns (uint64) {
// Complete transfer will give the Tokens to this Contract
// Unlike solana, we don't need to check that the emitter is a Portal contract as register_ scripts register all the Portal contracts
// and the completeTransfer function checks the emitter is a valid Portal contract on one of the chains it's registered with