1

The following code is a popular solidity ethereum function

function: swapExactETHForTokens(uint256 amountOutMin, address[] path, address to, uint256 deadline)

what should amountOutMin type look like in golang?

Here is what I try in golang

amountOutMin := 20
data, err := routerABI.Pack("swapExactETHForTokens", amountOutMin, path, to, deadline)

The error message: cannot use int as type ptr as argument

It is showed that amountOutMin is a pointer, while solidity's declaration is uint256. very confusing

Regards,

1 Answer 1

0

The uint Solidity type is a *big.Int in Go. So you must create a *big.Int variable and pass that to your contract call.

Example to set the amountOutMin correctly:

amountOutMin:= new(big.Int)
amountOutMin.SetString("5000000000000000", 10)  
data, err := routerABI.Pack("swapExactETHForTokens", amountOutMin, path, to, deadline)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.