Reputation: 1
I have read the article abount ERC165 that is enable us to detect which interface is implemented in a contract.
However, I found that some ERC721 tokens are a little bit diffrent from others, like cryptokitties and cryptohorse.
Are these different ERC721 tokens are both detected as erc721 token by wallet application.
And how does erc721 support wallet detect the type of tokens.
Upvotes: 0
Views: 3081
Reputation: 36263
Yes, some ERC-721 contracts do not follow the standard. The reason for most of them is because they were deployed before the ERC-721 standard was actually confirmed. One of these examples is CryptoKitties.
Use ERC-721 Validator that checks if a smart contract fully follows the ERC-721 standard: https://erc721validator.org
Upvotes: 3
Reputation: 7370
In golang you can detect if a contract is a token by calling the EVM and checking the output, kind of like this:
// Getting token Decimals
input, err = erc20_token_abi.Pack("decimals")
if err!=nil {
utils.Fatalf("packing input for decimals failed: %v",err)
}
msg=types.NewMessage(fake_src_addr,addr,0,value,gas_limit,gas_price,input,false)
evm_ctx=core.NewEVMContext(msg,block_header,chain,nil)
ethvirmac=vm.NewEVM(evm_ctx,statedb,bconf,vm_cfg)
gp=new(core.GasPool).AddGas(math.MaxBig256)
ret,gas,failed,err=core.ApplyMessage(ethvirmac,msg,gp)
tok.decimals_found=false
if (failed) {
log.Info(fmt.Sprintf("vm err for decimals: %v, failed=%v",err,failed))
}
if err!=nil {
log.Info(fmt.Sprintf("getting 'decimals' caused error in vm: %v",err))
}
if !((err!=nil) || (failed)) {
int_output:=new(uint8)
err=erc20_token_abi.Unpack(int_output,"decimals",ret)
if err!=nil {
log.Info(fmt.Sprintf("Contract %v: can;t upack decimals: %v",hex.EncodeToString(addr.Bytes()),err))
} else {
tok.decimals=int32(*int_output)
tok.decimals_found=true
}
}
But if you don't want to get your hands dirty by working with the EVM directly, you can check event signatures:
erc20_approval_signature,_ = hex.DecodeString("8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925")
erc20_transfer_signature,_ = hex.DecodeString("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
These are located at event.Topics[0], so if Topics[0] matches to the above string the probability that the contract is ERC20 token is high. If you collect all the event of a contract, and derive a summary of what methods does it use, you can decide either it is a ERC20 or ERC721
Upvotes: 1