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

ChargeAssetTxPayment::asset_id #298

Open
puneetjindal3 opened this issue Sep 23, 2022 · 1 comment
Open

ChargeAssetTxPayment::asset_id #298

puneetjindal3 opened this issue Sep 23, 2022 · 1 comment

Comments

@puneetjindal3
Copy link

puneetjindal3 commented Sep 23, 2022

Hi,

I'm using the below code for transferring the balance from alice to bob but facing the below issue:-

`
func SendData(sign, data []byte) error {
// This sample shows how to create a transaction to make a transfer from one an account to another.

// Instantiate the API
api, err := gsrpc.NewSubstrateAPI(os.Getenv("B_HOST"))
if err != nil {
	panic(err)
}

meta, err := api.RPC.State.GetMetadataLatest()
if err != nil {
	panic(err)
}

// Create a call, transferring 12345 units to Bob
bob, err := types.NewMultiAddressFromHexAccountID("0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
if err != nil {
	panic(err)
}

// 1 unit of transfer
bal, ok := new(big.Int).SetString("100000000000000", 10)
if !ok {
	panic(fmt.Errorf("failed to convert balance"))
}

c, err := types.NewCall(meta, "Balances.dfs_transfer_keep_alive", bob, types.NewUCompact(bal))
if err != nil {
	panic(err)
}

// Create the extrinsic
ext := types.NewExtrinsic(c)

genesisHash, err := api.RPC.Chain.GetBlockHash(0)
if err != nil {
	panic(err)
}

rv, err := api.RPC.State.GetRuntimeVersionLatest()
if err != nil {
	panic(err)
}

key, err := types.CreateStorageKey(meta, "System", "Account", signature.TestKeyringPairAlice.PublicKey)
if err != nil {
	panic(err)
}

var accountInfo types.AccountInfo
ok, err = api.RPC.State.GetStorageLatest(key, &accountInfo)
if err != nil || !ok {
	panic(err)
}

nonce := uint32(accountInfo.Nonce)
o := types.SignatureOptions{
	BlockHash:          genesisHash,
	Era:                types.ExtrinsicEra{IsMortalEra: false},
	GenesisHash:        genesisHash,
	Nonce:              types.NewUCompactFromUInt(uint64(nonce)),
	SpecVersion:        rv.SpecVersion,
	Tip:                types.NewUCompactFromUInt(100),
	TransactionVersion: rv.TransactionVersion,
}

// Sign the transaction using Alice's default account
err = ext.Sign(signature.TestKeyringPairAlice, o)
if err != nil {
	panic(err)
}

// Send the extrinsic
_, err = api.RPC.Author.SubmitExtrinsic(ext)
if err != nil {
	panic(err)
}

fmt.Printf("Balance transferred from Alice to Bob: %v\n", bal.String())

}
`

Code:1002
Message:"Verification Error: Runtime error: Execution failed: ApiError(FailedToConvertParameter { function: "validate_transaction", parameter: "tx", error: Error { cause: Some(Error { cause: None, desc: "unexpected first byte decoding Option" }), desc: "Could not decode ChargeAssetTxPayment::asset_id" } })"

How can i resolve this issue or what I'm doing wrong in above program snippet?

@cdamian
Copy link
Contributor

cdamian commented Dec 5, 2023

Hi @puneetjindal3, this is most likely due to the fact that the signature options required in your case require more than a normal UCompact tip.

Please refer to - https://github.com/centrifuge/go-substrate-rpc-client/blob/master/registry/retriever/extrinsic_retriever_live_test.go#L42 and try adjusting the SignatureOptions on your side accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants