Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling a smart contract action #200

Open
uo257724 opened this issue Jan 19, 2023 · 2 comments
Open

Calling a smart contract action #200

uo257724 opened this issue Jan 19, 2023 · 2 comments
Labels
needs info Author needs to provide more info to help/reproduce

Comments

@uo257724
Copy link

Is there any smart contract action example done in the repository? if not, can you write one?
Im doing a transaction to call and action to register data in a table and all i got are assert errors.

@maoueh
Copy link
Contributor

maoueh commented Jan 19, 2023

https://github.com/eoscanada/eos-go/blob/develop/example_api_transfer_eos_test.go#L38 shows a transfer action, should be a good starting point.

Provide an example and I could help further.

@maoueh maoueh added the needs info Author needs to provide more info to help/reproduce label Jan 19, 2023
@uo257724
Copy link
Author

The code I'm using:

        transferPermissionLevel, err := eos.NewPermissionLevel(from + "@active")
	if err != nil {
		panic("Error creating permission level")
	}	
         // Fills in the transaction header information like ref block, delays and expiration is set to 30s
	txOpts := &eos.TxOptions{}
	err = txOpts.FillFromChain(context.Background(), api)
	if err != nil {
		panic("Error filling tx options")
	}

	trx := eos.NewTransaction([]*eos.Action{
		{
			Account:       eos.AN(contractName),  // The contract that will execute the action
			Name:          eos.ActN("addopname"), // The action name
			Authorization: []eos.PermissionLevel{transferPermissionLevel},
			ActionData: eos.NewActionData(OperationNamePost{
				op_id:         1,                 //eos.Uint64
				op_name:       "aaa",             //string
				fields:        fields,            //[]string
				types:         types,             //[]string
				offchain_data: eos.Checksum256{}, //eos.Checksum256
			}),
		},
		}, txOpts)

		// keyBag := eos.NewKeyBag()
		keyBag := &eos.KeyBag{}
		err = keyBag.ImportPrivateKey(context.Background(), fromPrivateKey)
		if err != nil {
			panic(fmt.Errorf("import private key: %w", err))
		}
		api.SetSigner(keyBag)

		_, packedTx, err := api.SignTransaction(context.Background(), trx, txOpts.ChainID, eos.CompressionNone)
		if err != nil {
			panic(fmt.Errorf("sign transaction: %w", err))
		}
		response, err := api.PushTransaction(context.Background(), packedTx)
		if err != nil {
			panic(fmt.Errorf("push transaction: %w", err))
		}

		fmt.Printf("Transaction [%s] submitted to the network succesfully.\n", hex.EncodeToString(response.Processed.ID))

and the error I'm getting is this:
sign transaction: get_required_keys: Internal Service Error: Invalid packed transaction: Failed to deserialize data for dopcontract:addopname: Failed to deserialize variant: Invalid transaction

Also, the struct i use for the transaction, have the fields and types that are in the transaction object.

I was following this example (link) but i have made some changes looking others examples.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info Author needs to provide more info to help/reproduce
Projects
None yet
Development

No branches or pull requests

2 participants