Error when deploying Ethereum contract: Unable to pass argument
As an Ethereum developer, you are not the only one facing this issue. In this article, we will explore the reasons for the “TypeError: unsupported addressable value” error when deploying a contract with parameters.
What is happening in your code?
Let’s take a closer look at the code from your unit test:
const args = [/ some arguments /];
const certification = new Certification(args);
In this case, the args array contains multiple values (e.g. addresses, strings, or other Ethereum objects). However, if you pass these arguments to the new Certification(args) constructor, it will attempt to create an instance of the Certification contract using the & operator, which is not a valid way to pass arguments in JavaScript.
Why does this error occur?
The reason for this error lies in the way Ethereum contracts work. When you call a function in a smart contract, for example “Certification”, only one argument is expected: the address of the instance object that receives the result. If you use the “&” operator with multiple arguments (e.g. “[ “address” ]”), you are passing an array of values to the contract, which is invalid.
What can you do to fix this issue?
To fix this error, you need to pass a single argument to the contract instead of an array. Here are some possible solutions:
1. Pass only one parameter
Instead of using “&” with multiple arguments, pass only one value:
“JavaScript”
const args = [/ some value /];
const certification = new Certification(args);
“”
This should fix the problem.
2. Use JSON.stringify() to convert values to strings
If you pass a value that can be converted to a string using JSON.stringify()
, you can pass it as a string:
const args = [JSON.stringify({ / some value / })];
// or
const args = [/ some value /];
The reason for this is that JSON objects are serializable, so any value with properties like an address
field will be converted to a string.
3. Wrap the argument in an object
Another possible solution is to wrap the argument in an object:
const args = { address: "some_address" };
const certification = new Certification(args);
This creates a new object with only one property that can be passed as a single value.
Conclusion
In summary, when providing contracts with parameters, it is important to pass the correct argument format. By using &
with multiple arguments or wrapping values in an object, you will be able to resolve the TypeError: unsupported addressable value
error and successfully deploy your contract.
Remember to always test your code thoroughly to ensure that issues are resolved before deploying your contracts to the Ethereum blockchain. Happy coding!