Skip to content

ERC20 Bank Berachain ​

Git Source

The ERC20 Bank precompile serves as an interface to Berachain’s ERC20 Bank module. It is designed to facilitate the conversion between ERC20 tokens and Cosmos coins within the Cosmos ecosystem. It allows users to transfer tokens between the two formats and provides a seamless way to interact with both types of assets.

The IERC20BankModule interface defines several events, such as TransferCoinToErc20and TransferErc20ToCoin, which are emitted when specific actions occur within the module. These events help track the movement of tokens and provide transparency for users and developers.

The interface also includes read methods, such as coinDenomForERC20Address and erc20AddressForCoinDenom, which allow users to query the corresponding Cosmos coin denomination for a given ERC20 token address and vice versa.

Additionally, the interface provides write methods for transferring tokens between ERC20 and Cosmos coins. These methods enable users to transfer tokens between their own accounts or between different accounts, depending on the specific method used.

Lastly, the performBankTransfer method allows BERC20 contracts to perform bank transfers between two addresses, enabling seamless integration with the Cosmos bank module.

In summary, the IERC20BankModule Interface enables developers and users to interact with both ERC20 tokens and Cosmos coins within the Cosmos ecosystem. It provides a set of methods for transferring tokens between the two formats, querying the corresponding assets, and performing bank transfers, making it a valuable tool for managing and interacting with digital assets in the Cosmos ecosystem.

Note: Link to existing contract ABI's can be found on Github here.

Interface of berachain's erc20 bank module's precompiled contract

Functions ​

coinDenomForERC20Address ​

coinDenomForERC20Address returns the SDK coin denomination for the given ERC20 address.

solidity
function coinDenomForERC20Address(IERC20 token) external view returns (string memory);
function coinDenomForERC20Address(IERC20 token) external view returns (string memory);

Parameters

NameTypeDescription
tokenIERC20the ERC20 token being queried for

erc20AddressForCoinDenom ​

erc20AddressForCoinDenom returns the ERC20 address for the given SDK coin denomination.

solidity
function erc20AddressForCoinDenom(string calldata denom) external view returns (IERC20);
function erc20AddressForCoinDenom(string calldata denom) external view returns (IERC20);

Parameters

NameTypeDescription
denomstringthe denomination of the SDK coin being queried for

transferCoinToERC20 ​

transferCoinToERC20 transfers amount SDK coins to ERC20 tokens for msg.sender

solidity
function transferCoinToERC20(string calldata denom, uint256 amount) external returns (bool);
function transferCoinToERC20(string calldata denom, uint256 amount) external returns (bool);

Parameters

NameTypeDescription
denomstringthe denomination of the SDK coin being transferred from
amountuint256the amount of coins to transfer

transferCoinToERC20From ​

transferCoinToERC20From transfers amount SDK coins to ERC20 tokens from owner to recipient

solidity
function transferCoinToERC20From(string calldata denom, address owner, address recipient, uint256 amount)
    external
    returns (bool);
function transferCoinToERC20From(string calldata denom, address owner, address recipient, uint256 amount)
    external
    returns (bool);

Parameters

NameTypeDescription
denomstringthe denomination of the SDK coin being transferred from
owneraddressthe address of the owner of the coins
recipientaddressthe address of the recipient of the tokens
amountuint256the amount of coins to transfer

transferCoinToERC20To ​

transferCoinToERC20To transfers amount SDK coins to ERC20 tokens from msg.sender to recipient

solidity
function transferCoinToERC20To(string calldata denom, address recipient, uint256 amount) external returns (bool);
function transferCoinToERC20To(string calldata denom, address recipient, uint256 amount) external returns (bool);

Parameters

NameTypeDescription
denomstringthe denomination of the SDK coin being transferred from
recipientaddressthe address of the recipient of the tokens
amountuint256the amount of coins to transfer

transferERC20ToCoin ​

transferERC20ToCoin transfers amount ERC20 tokens to SDK coins for msg.sender

solidity
function transferERC20ToCoin(IERC20 token, uint256 amount) external returns (bool);
function transferERC20ToCoin(IERC20 token, uint256 amount) external returns (bool);

Parameters

NameTypeDescription
tokenIERC20the ERC20 token being transferred from
amountuint256the amount of tokens to transfer

transferERC20ToCoinFrom ​

transferERC20ToCoinFrom transfers amount ERC20 tokens to SDK coins from owner to recipient

solidity
function transferERC20ToCoinFrom(IERC20 token, address owner, address recipient, uint256 amount)
    external
    returns (bool);
function transferERC20ToCoinFrom(IERC20 token, address owner, address recipient, uint256 amount)
    external
    returns (bool);

Parameters

NameTypeDescription
tokenIERC20the ERC20 token being transferred from
owneraddressthe address of the owner of the coins
recipientaddressthe address of the recipient of the tokens
amountuint256the amount of tokens to transfer

transferERC20ToCoinTo ​

transferERC20ToCoinTo transfers amount ERC20 tokens to SDK coins from msg.sender to recipient

solidity
function transferERC20ToCoinTo(IERC20 token, address recipient, uint256 amount) external returns (bool);
function transferERC20ToCoinTo(IERC20 token, address recipient, uint256 amount) external returns (bool);

Parameters

NameTypeDescription
tokenIERC20the ERC20 token being transferred from
recipientaddressthe address of the recipient of the tokens
amountuint256the amount of tokens to transfer

performBankTransfer ​

it is assumed msg.sender is a BeraERC20 contract.

performBankTransfer performs a bank module transfer.

solidity
function performBankTransfer(address owner, address recipient, uint256 amount) external returns (bool);
function performBankTransfer(address owner, address recipient, uint256 amount) external returns (bool);

Parameters

NameTypeDescription
owneraddressthe user who is getting their balance decreased.
recipientaddressthe user who is gettting their balance increased.
amountuint256the amount of coins to transfer.

Events ​

TransferCoinToErc20 ​

Emitted by the erc20 bank module when coins (coinSent) are transferred from SDK coin to an ERC20 token from owner to recipient.

solidity
event TransferCoinToErc20(
    address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinSent
);
event TransferCoinToErc20(
    address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinSent
);

Parameters

NameTypeDescription
tokenaddressthe ERC20 token being transferred to
owneraddressthe address of the owner of the coins
recipientaddressthe address of the recipient of the tokens
coinSentCosmos.Cointhe amount of coins sent (in the sent SDK Coin denomination)

TransferErc20ToCoin ​

Emitted by the erc20 bank module when ERC20 token is transferred to an SDK coin (coinReceived) from owner to recipient.

solidity
event TransferErc20ToCoin(
    address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinReceived
);
event TransferErc20ToCoin(
    address indexed token, address indexed owner, address indexed recipient, Cosmos.Coin coinReceived
);

Parameters

NameTypeDescription
tokenaddressthe ERC20 token being transferred from
owneraddressthe address of the owner of the tokens
recipientaddressthe address of the recipient of the coins
coinReceivedCosmos.Cointhe amount of coins received (in the received SDK Coin denomination)

Erc20CreatedFromCoin ​

Emitted by the erc20 bank module when a coin is first transferred to ERC20, a new ERC20 token is deployed, and the ERC20 mapping is instantiated.

solidity
event Erc20CreatedFromCoin(address indexed token, string denom);
event Erc20CreatedFromCoin(address indexed token, string denom);

Parameters

NameTypeDescription
tokenaddressthe address of the newly deployed ERC20 token
denomstringthe denomination of the SDK coin being transferred from

CoinCreatedFromErc20 ​

Emitted by the erc20 bank module when an ERC20 token is first transferred to coin, and the coin mapping is instantiated.

solidity
event CoinCreatedFromErc20(address indexed token, string denom);
event CoinCreatedFromErc20(address indexed token, string denom);

Parameters

NameTypeDescription
tokenaddressthe address of the ERC20 token being transferred from
denomstringthe denomination of the newly created SDK coin