I'm studying the Solidity, and I want to understand how to interact with a smartcotnract and etherjs.
I have a simple function like this:
function buyNumber(uint256 _number) public payable {
if(msg.value < 0.1 ether){
revert("more eth!");
}
...todoStuff
}
And I have the test
const tx = {
from: owner.address,
to: myContract.address,
value: ethers.utils.parseEther('0.1'),
data: '0x4b729aff0000000000000000000000000000000000000000000000000000000000000001'
}
let sendTx = await owner.sendTransaction(tx);
console.log(sendTx)
Now, the transaction works because I get 0x4b729aff0000000000000000000000000000000000000000000000000000000000000001 the function signature and parameters with
let iface = new ethers.utils.Interface(ABI)
iface.encodeFunctionData("buyNumber", [ 1 ])
0x4b729aff0000000000000000000000000000000000000000000000000000000000000001
Can I get the same result in easy way? How can I call a function in my contract with params? I could put the msg.value as parameter, but I prefer to use less parameters