Here's my current issue...
I have a function in a Solidity smart contract that takes two arguments:
function safeMint(address _to, string memory _uri)
public
{
// do things here
}
I'm developing a JavaScript Object for my FrontEnd to deal with it. The object uses ethers.js to connect to the smart contract and call functions. I want to be able to pass the object the function name and arguments, so that the object makes the calls and returns any needed thing. My reading function is currently working:
/**
* @function callFunction - Makes a read-only call to the smart contract's specified function
* @param {string} _functionName - the name of the function to be called
* @param {...any} _args the arguments to be passed on to the function
* @returns result of the function call
*/
async callFunction(_functionName, ..._args) {
if(this.#readerContract != null && this.#readerContract != undefined)
return await this.#readerContract.functions[_functionName](_args);
}
/**
* @function sendFunction - Makes a full call to the smart contract's specified function
* @param {string} _functionName - the name of the function to be called
* @param {...any} _args the arguments to be passed on to the function
* @returns the promise of the called function
*/sendFunction(_functionName, ..._args) {
if(this.#fullContract != null && this.#fullContract != undefined)
return this.#fullContract.functions[_functionName](_args);
}
when I use it with the following code:
result = await smartPlug.callFunction("getTokenCap");
How do I make a call to a smart contract method using arguments? I have tried the following:
result = await sp.sendFunction("setUserName", ebUserName.value);
But I get an error that says: "Paused on promise rejection - TypeError: str.charCodeAt is not a function" running it in Google Chrome.
call
orapply
: stackoverflow.com/questions/8659390/….return this.#fullContract.functions[_functionName](..._args);
I will test it now, and return soon with the results.