简体   繁体   English

在 erc721/erc20 代币之间共享 ABI?

[英]Sharing ABI between erc721/erc20 Tokens?

Say I have an ethereum contract that uses erc721 protocol.假设我有一个使用 erc721 协议的以太坊合约。 When I create a new contract object using web3.当我使用 web3 创建新合约 object 时。

 const contract = new web3.eth.contract(contractABI, contractAddress);

Is it possible to include only the abi of the parent erc721 contract, aslong as I only use functions that are within the erc721 scope?只要我只使用 erc721 scope 中的函数,是否可以只包含父 erc721 合约的 abi? Or does web3 require the full abi?还是 web3 需要完整的 abi?

I want to know if I can call upon multiple erc721 tokens sharing one abi.我想知道我是否可以调用共享一个 abi 的多个 erc721 令牌。 Thanks!谢谢!

Yes, you can use a common ABI for multiple contracts.是的,您可以将一个通用 ABI 用于多个合同。 The limitation is that you'll be able to use only the methods and properties defined in the ABI.限制是您只能使用 ABI 中定义的方法和属性。

And the other way around: If you call a method that is defined in the ABI but not in the actual contract, the contract will try to run the fallback function.反之亦然:如果您调用在 ABI 中定义但未在实际合约中定义的方法,则合约将尝试运行后备 function。


web3 needs the ABI to be able to tell how to encode the function arguments and return values. web3需要 ABI 能够告诉如何编码 function arguments 并返回值。 So if you call foo(1, 2) should it encode as foo(uint8 1, uint64 2) or foo(bool true, uint256 2) ?因此,如果您调用foo(1, 2)它应该编码为foo(uint8 1, uint64 2)还是foo(bool true, uint256 2)

But it's really "just" a helper to generate the correct functions in the contract.methods.* list and their encoding map.但它真的“只是”一个助手,可以在contract.methods.*列表及其编码 map 中生成正确的函数。 So if you don't need some of them, you can skip this by not defining them in the ABI.因此,如果您不需要其中的一些,您可以通过不在 ABI 中定义它们来跳过此步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM