Native Ether
Last updated
Last updated
This guide provides a step-by-step approach for developers looking to implement the swap mechanism for native Ethers
within the Swaplace project. The process involves defining the swap parameters, encoding configurations, and finally creating the swap.
Check the testsuit for this case
When dealing with native Ether in swaps, alongside ERC20, ERC721 and ERC1155 tokens, the key parameters remain similar but with added attention to the Ether value being transferred:
Owner: The Ethereum address initiating the swap.
Allowed: The address authorized to accept the swap. A zero address implies anyone can accept.
Expiry: A future timestamp indicating when the swap offer expires.
Recipient: Specifies who receives the Ether involved in the swap. 0
denotes the acceptor, while values 1
through 255
refer to the swap owner.
Value: The amount of Ether involved in the swap, with a precision of up to 6 decimals.
Assets: An array detailing the assets being offered in the swap, including token addresses, IDs, and amounts.
Asking: An array specifying what assets are requested in exchange.
Define the parameters for your swap, including the addresses of the tokens involved, their amounts, and configuration details like expiry and recipient.
Determine the amount of Ether to send with the swap. Use utility functions like ethers.utils.parseEther
to convert Ether units to wei, the smallest unit of Ether.
Encode the allowed address, expiry timestamp, recipient type, and Ether value into a single uint256 value using encodeConfig
.
Compose the swap structure by calling the function called omposeSwap
, passing in the owner's address, encoded configuration, and arrays detailing the bid and ask components.
Finally, create the swap by calling the createSwap
function on the Swaplace
contract, passing in the composed swap structure and the Ether value as part of the transaction options.
You can check the full code