Collats NFT Vault
Details
The vault is the contract that manages the amount of Collats backing an ERC721 asset. It keeps track of the amount of Collats that an NFT has assigned.
Ethereum Mainnet
0x157CD665f569E916A38d9607D7fB28D3083c203b
Polygon Mainnet
0x157CD665f569E916A38d9607D7fB28D3083c203b
Binance Smart Chain Mainnet
0x157CD665f569E916A38d9607D7fB28D3083c203b
Interface
// SPDX-License-Identifier: MIT
pragma solidity 0.8.14;
interface ICollatsNFTVault {
function buyAndAddCollats(address nftAddress, uint256 tokenId)
external
payable
returns (uint256 collatsBought);
function buyAndAddCollatsWithERC20(
address nftAddress,
uint256 tokenId,
address token,
uint256 amount
) external returns (uint256 collatsBought);
function addCollats(
address nftAddress,
uint256 tokenId,
uint256 amount
) external;
function addCollatsInBulk(
address[] memory nftAddresses,
uint256[] memory tokenIds,
uint256[] memory amounts
) external;
function withdrawCollats(
address to,
address nftAddress,
uint256 tokenId,
uint256 amount
) external returns (bool);
function balanceOf(address nftAddress, uint256 tokenId)
external
view
returns (uint256);
}
The ICollatsNFTVault interface defines a contract that allows users to buy and add "collats" to a specific non-fungible token (NFT) identified by its address and token ID. It also allows users to add collats to an NFT in bulk, withdraw collats from an NFT, and check the balance of collats for a specific NFT.
The buyAndAddCollats function allows users to buy and add collats to an NFT by paying with Ether. The buyAndAddCollatsWithERC20 function allows users to buy and add collats to an NFT by paying with a specific ERC20 token. The addCollats function allows users to add a specific amount of collats to an NFT. The addCollatsInBulk function allows users to add collats to multiple NFTs in a single transaction. The withdrawCollats function allows users to withdraw a specific amount of collats from an NFT and send them to a specified address. The balanceOf function allows users to check the balance of collats for a specific NFT.
Contract to contract example
Here is sample code in Solidity 8 that demonstrates how to call the functions of the ICollatsNFTVault interface from another contract:
In this example, the contract MyContract calls the functions of the ICollatsNFTVault contract by calling the corresponding functions on an instance of the ICollatsNFTVault contract, which is stored in the collatsNFTVault variable. The contract address of the deployed ICollatsNFTVault contract needs to be provided when the collatsNFTVault variable is initialized.
The return values of the buyAndAddCollats and buyAndAddCollatsWithERC20 functions are stored in the variables collatsBought, which can then be used for further processing. The withdrawCollats function returns a boolean value indicating whether the withdrawal was successful or not, which can be checked in an if statement. The balanceOf function returns the balance of the specified NFT for the given token ID, which can be stored in the balance variable and used for further processing.
Note that the buyAndAddCollats function is marked payable, which means that it can accept Ether as a payment. Make sure to provide enough Ether when calling the function, or the transaction will fail.
ICollatsNFTVault ABI
JavaScript
Web3.js
Here is an example of how you can call the functions of the CollatsNFTVault contract from JavaScript using Web3:
In this example, the functions of the CollatsNFTVault contract are called using the send method of the Contract object, which sends a transaction to the Ethereum network. The buyAndAddCollats function is marked payable, which means that it can accept Ether as a payment.
The addCollats, addCollatsInBulk, and withdrawCollats functions do not have any return values, so the returned value of the send method can be used to check the status of the transaction (e.g. whether it was mined successfully or not). The balanceOf function is a view function, which means that it does not modify the state of the contract and does not need to be called with the send method. Instead, it can be called with the call method, which returns the value of the function without sending a transaction.
You can call these functions in your code by passing the required parameters. For example:
Ethers.js
Here is an example of how you can call the functions of the CollatsNFTVault contract from JavaScript using Ethers.js:
You can call these functions in your code by passing the required parameters. For example:
This script calls all the functions of the CollatsNFTVault contract and logs the results to the console. It calls the buyAndAddCollats function, the buyAndAddCollatsWithERC20 function, the addCollats function, the addCollatsInBulk function, the withdrawCollats function, and the balanceOf function.
Keep in mind that this script is just an example, and you may need to modify it to fit your specific needs. You will also need to handle errors and handle the case where the JsonRpcProvider is not available.
Last updated