Skip to main content
added 5 characters in body
Source Link

After digging in geth documentation I found out the solution for my problem. Here an example how to encode single type as well as tuple without provided abi:

name := "Crown"
symbol := "Crown"
decimals := 18

stringAbiType, _ := abi.NewType("string", "", nil)
uint256AbiType, _ := abi.NewType("uint256", "", nil)
bytesAbiType, _ := abi.NewType("bytes", "", nil)

nameEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(name)
if err != nil {
    return nil, err
}
symbolEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(symbol)
if err != nil {
    return nil, err
}
decimalsEncoded, err := abi.Arguments{{Type: uint256AbiType}}.Pack(big.NewInt(int64(decimals)))
if err != nil {
    return nil, err
}

returntuple, _ := abi.Arguments{
    {Type: bytesAbiType},
    {Type: bytesAbiType},
    {Type: bytesAbiType},
}.Pack(nameEncoded, symbolEncoded, decimalsEncoded)

After digging in geth documentation I found out the solution for my problem. Here an example how to encode single type as well as tuple without provided abi:

name := "Crown"
symbol := "Crown"
decimals := 18

stringAbiType, _ := abi.NewType("string", "", nil)
uint256AbiType, _ := abi.NewType("uint256", "", nil)
bytesAbiType, _ := abi.NewType("bytes", "", nil)

nameEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(name)
if err != nil {
    return nil, err
}
symbolEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(symbol)
if err != nil {
    return nil, err
}
decimalsEncoded, err := abi.Arguments{{Type: uint256AbiType}}.Pack(big.NewInt(int64(decimals)))
if err != nil {
    return nil, err
}

return abi.Arguments{
    {Type: bytesAbiType},
    {Type: bytesAbiType},
    {Type: bytesAbiType},
}.Pack(nameEncoded, symbolEncoded, decimalsEncoded)

After digging in geth documentation I found out the solution for my problem. Here an example how to encode single type as well as tuple without provided abi:

name := "Crown"
symbol := "Crown"
decimals := 18

stringAbiType, _ := abi.NewType("string", "", nil)
uint256AbiType, _ := abi.NewType("uint256", "", nil)
bytesAbiType, _ := abi.NewType("bytes", "", nil)

nameEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(name)
if err != nil {
    return nil, err
}
symbolEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(symbol)
if err != nil {
    return nil, err
}
decimalsEncoded, err := abi.Arguments{{Type: uint256AbiType}}.Pack(big.NewInt(int64(decimals)))
if err != nil {
    return nil, err
}

tuple, _ := abi.Arguments{
    {Type: bytesAbiType},
    {Type: bytesAbiType},
    {Type: bytesAbiType},
}.Pack(nameEncoded, symbolEncoded, decimalsEncoded)
Source Link

After digging in geth documentation I found out the solution for my problem. Here an example how to encode single type as well as tuple without provided abi:

name := "Crown"
symbol := "Crown"
decimals := 18

stringAbiType, _ := abi.NewType("string", "", nil)
uint256AbiType, _ := abi.NewType("uint256", "", nil)
bytesAbiType, _ := abi.NewType("bytes", "", nil)

nameEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(name)
if err != nil {
    return nil, err
}
symbolEncoded, err := abi.Arguments{{Type: stringAbiType}}.Pack(symbol)
if err != nil {
    return nil, err
}
decimalsEncoded, err := abi.Arguments{{Type: uint256AbiType}}.Pack(big.NewInt(int64(decimals)))
if err != nil {
    return nil, err
}

return abi.Arguments{
    {Type: bytesAbiType},
    {Type: bytesAbiType},
    {Type: bytesAbiType},
}.Pack(nameEncoded, symbolEncoded, decimalsEncoded)