-
Ethers Version6.6.2 Search Termsbytes name symbol erc20 Describe the ProblemI'm trying to interact with the Maker token contract on Ethereum with address : 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2 Most tokens use strings for their names and symbols but this contract uses a bytes32 variable. I have changed the ABI to reflect the new type but Ethers throws an error when calling Code Snippetconst contract = new ethers.Contract(
contractAddress,
abi,
signer
)
const erc = contract.connect(walletAddress)
const name = await contract.name() // throws the error Contract ABI{
"_format": "hh-sol-artifact-1",
"contractName": "IERC20",
"sourceName": "contracts/interfaces/IERC20.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
} ErrorsError: could not decode result data (value="0x4d616b6572000000000000000000000000000000000000000000000000000000", info={ "method": "name", "signature": "name()" }, code=BAD_DATA, version=6.6.1)
at makeError (errors.ts:677:21)
at assert (errors.ts:694:25)
at _Interface.decodeFunctionResult (interface.ts:916:9)
at staticCallResult (contract.ts:324:35)
at async staticCall (contract.ts:281:24)
at async Proxy.name (contract.ts:329:41) EnvironmentEthereum (mainnet/ropsten/rinkeby/goerli) Environment (Other)No response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
From the ABI it appears that function name() public returns (bytes32);
function symbol() public returns (bytes32); Then you can use |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot, that was it ! It's working perfectly now. |
Beta Was this translation helpful? Give feedback.
From the ABI it appears that
bytes
type is being used for name and symbol, while you needbytes32
there.Then you can use
ethers.decodeBytes32String
util to process it.