Token Client | Abstracts NFT and token functionality for generic and elegant operations with tokens

TokenClient.sol is a smart contract that facilitates support for fungible and non-fungible token operations. You can add a set of TokenAbstraction implementations with read and transfer functions and without storage (as TokenERC20, TokenERC721 or TokenERC1155), which are responsible for calling the functions of each standard. It allows to generalize the functionality with tokens using the template pattern, and support new token standards using the proxy pattern.

In other words, instead of calling the different methods of each particular standard directly, you call the TokenClient and it calls the standards for you. Thanks to this, developing dApps like marketplaces or swappers that support many tokens is very easy and upgradeable, makes the code more elegant and saves you a lot of time.

function isStandard(address contractAddress) external view returns(bool);
function isOwner(Token calldata token, address account) external view returns (bool);
function isOwnerSet(TokenSet calldata tokenSet, address account) external view returns (bool);
function isApproved(Token calldata token, address account, address operator) external view returns (bool);
function isApprovedSet(TokenSet calldata tokenSet, address account, address operator) external view returns (bool);
function transfer(Token calldata token, address from, address to) external returns (bool);
function transferSet(TokenSet calldata tokenSet, address from, address to) external returns (bool);
struct Token
{
   bytes32 Standard;
   address Contract;
   bytes32 Id;
   uint256 Amount;  
}

struct TokenSet
{
   bytes32 Standard;
   address Contract;
   bytes32[] Ids;
   uint256[] Amounts;  
}

I have distributed it as npm package to start using it in my projects. Please give it a try!

npm i @danielabalde/token-client

More info and source code:

I would love to get some feedback from you! Any comments are welcome.

Thanks.

1 Like

New version includes balanceOf function and better README.

Could someone take a look please? I'm looking for some feedback.