Skip to content

Passing Optional Parameter using Go-SDK #49

@rudreshkoranne

Description

@rudreshkoranne

Hey there everyone!!!

I trying to invoke a Contract's method using the Go-SDK. The Method implementation is such:
public entry fun mint( validator: &signer, avatar_cid: String, public_key: vector<u8>, proxyaddress: Option<address> ) {}

And the Script I have written in go is below:

`func Mint(client aptos.Client, accountaptos.Account, avatarCID string, publicKey crypto.PublicKey, proxyAddress *aptos.AccountAddress) {
pubKeyBytes,  := bcs.Serialize(publicKey)
avatarBytes := []byte(avatarCID)

serializedAvatarBytes,  := bcs.SerializeBytes(avatarBytes)
proxyBytes := []byte{}

if proxyAddress != nil {
    proxyBytes,  = bcs.Serialize(proxyAddress)
}

rawTx, err := client.BuildTransaction(account.Address, aptos.TransactionPayload{
    Payload: &aptos.EntryFunction{
        Module: aptos.ModuleId{
            Address: MODULE_ADDRESS,
            Name:    MODULE_NAME,
        },
        Function: "mint_poa_nft",
        ArgTypes: []aptos.TypeTag{},
        Args: [][]byte{
            serializedAvatarBytes,
            pubKeyBytes,
            proxyBytes,
        },
    },
})}`

now the problem I'm facing is related to the proxy_address which is an optional parameter.
Can anyone please help me this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions