I want to send transaction via ethers and wallet connected to metamask with following code:
async redeemAllocation(idoId: number) {
const IRoot = new ethers.utils.Interface(JSON.stringify(RootAbi))
const addrRoot = "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
const smcRoot = new ethers.Contract(addrRoot, IRoot)
const investorIndex = await smcRoot.investorIndexFromProject(await this.signer!.getAddress(), idoId);
let project = await smcRoot.projectById(idoId);
const amount = project.amounts[investorIndex];
const data = IRoot.encodeFunctionData("redeemAllocation", [idoId, amount]);
this.signer!.sendTransaction({to: addrRoot, data: data}).then(async (tx) => {
console.log('transaction sended')
project = await smcRoot.projectById(idoId);
console.log(project.redeemed[investorIndex])
});
And get an error saying Errors encountered in param 1: Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/0: QUANTITY, Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/1: { blockNumber: QUANTITY }, Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/2: { blockHash: DATA, requireCanonical: boolean | undefined }, Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/3: "earliest" | "latest" | "pending"
.
redeemAllocation
abi:
{
"inputs": [
{
"internalType": "uint256",
"name": "projectId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "redeemAllocation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
I guess the problem can be in IRoot.encodeFunctionData
, but still don't get the reason clearly.