Subgraph indexing failing due to mapping abortion with reason – ethereum value is not an address, from one of the handlers. I understand the issue if from the handlePaymentExpenseCreated()
function but I'm unable to pinpoint the issue. Everything seems right. Thank you in advance.
Here's the image of the logs.
The subgraph schema
type ActiveExpense @entity {
id: ID!
payer: Bytes!
to: Bytes!
splitBy: [Bytes!]!
splitAmounts: [BigInt!]!
expenseIndex: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
The mapping handler function
export function handlePaymentExpenseCreated(
event: PaymentExpenseCreatedEvent
): void {
const id: string = getIdFromParams(event.params.param0, event.params.param4);
let activeExpense = ActiveExpense.load(id);
let newExpense = new PaymentExpenseCreated(id);
if (!activeExpense) {
activeExpense = new ActiveExpense(id);
}
newExpense.payer = event.params.param0;
activeExpense.payer = event.params.param0;
newExpense.to = event.params.param1;
activeExpense.to = event.params.param1;
// two different methods of assinging type Address[] to type Bytes[]
const splitAddresses = event.params.param2.map<Bytes>(
(address: Bytes) => address
);
newExpense.splitBy = splitAddresses;
activeExpense.splitBy = changetype<Bytes[]>(event.params.param2);
newExpense.splitAmounts = event.params.param3;
activeExpense.splitAmounts = event.params.param3;
newExpense.expenseIndex = event.params.param4;
activeExpense.expenseIndex = event.params.param4;
newExpense.blockTimestamp = event.block.timestamp;
activeExpense.blockTimestamp = event.block.timestamp;
newExpense.transactionHash = event.transaction.hash;
activeExpense.transactionHash = event.transaction.hash;
newExpense.save();
activeExpense.save();
}
Subgraph yaml file
specVersion: 0.0.5
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum
name: DeSplit
network: goerli
source:
address: "0xA74c0C03A05B94a67FDc09351b312f122308335d"
abi: DeSplit
startBlock: 8402740
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- ExpenseSettled
- PaymentExpenseCreated
abis:
- name: DeSplit
file: ./abis/DeSplit.json
eventHandlers:
- event: ExpenseSettled(address,address,uint256,uint256)
handler: handleExpenseSettled
- event: PaymentExpenseCreated(address,address,address[],uint256[],uint256)
handler: handlePaymentExpenseCreated
file: ./src/de-split.ts
The event emitted from the contract and link to the contract
emit PaymentExpenseCreated(
msg.sender,
_to, //address
_splitBy, //address[]
_splitAmount, // uint256[]
expenses.length - 1 //uint256
);
https://goerli.etherscan.io/address/0xA74c0C03A05B94a67FDc09351b312f122308335d
Best Answer
It took me two days to solve the same error. First of all, the event on your contract has no parameter name, which makes it impossible for the subgraph to map accurately. If you can't change the contract, you can try another method, manually mapping it to your subgraph event by modifying the abi in the abis/ folder.