I am trying to execute the lending
call function from this Smart Contract.
The following code is JavaScript using Ethers.js to make the integration with the Smart Contract.
const contractAddress = "0x1C4E9F87c7F2bCd80c89A1999d776461d41545b9";
const provider = new ethers.providers.JsonRpcProvider(
"https://rpc.ankr.com/bsc"
);
const signer = new ethers.Wallet(privateKey, provider);
const contract = new ethers.Contract(contractAddress, ABI, signer);
const lending = async () => {
const id = 992581;
const tokenId = 16587857756452;
const price = 500000000000;
const expiredAt = Date.now() + 60;
const messageHash = ethers.utils.solidityKeccak256(
["uint256", "uint256", "uint256", "uint256"],
[id, tokenId, price, expiredAt]
);
const signingKey = new SigningKey("0x" + privateKey);
const signature = signingKey.signDigest(messageHash);
const signatureString = ethers.utils.joinSignature(signature);
const tx = await contract.lending(
id,
tokenId,
price,
expiredAt,
signatureString,
{
gasLimit: 50000,
}
);
const receipt = await tx.wait();
console.log(receipt);
};
This is the trx showing the error.
The Smart Contract code that verifies the signature is this one.
function verifyLendingSig(
uint256 _id,
uint256 _tokenId,
uint256 _price,
uint256 _expiredAt,
bytes calldata _signature
) public view {
bytes32 criteriaMessageHash = keccak256(
abi.encodePacked(_id, _tokenId, _price, _expiredAt)
);
bytes32 ethSignedMessageHash = ECDSA.toEthSignedMessageHash(
criteriaMessageHash
);
require(
ECDSA.recover(ethSignedMessageHash, _signature) == signer,
"invalid signature"
);
}
Can someone show me how I can generate the signature for the lending
call?