patractlabs / redspot

Redspot is an Substrate pallet-contracts (ink!) development environment. Compile your contracts and run them on a different networks. Redspot's core forks from Hardhat but changed a lot to suit substrate.
https://redspot.patract.io/
Other
67 stars 22 forks source link

buildPopulate prepends extra data to payload #161

Closed forgetso closed 2 years ago

forgetso commented 2 years ago

Redspot Version Master

When I use the Polkadot apps interface to generate a payload for a contract call I get the following value in the UI:

0x42b45efa15e7f4d24384ccf8e79cdd2c41eb6c2e5e14608020a2ab3b635f22988dbaa44590b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe2200

This works when I submit it as the payload from the submit extrinsics page.

When I use buildPopulate in redspot I get a hash which is very similar but not quite the same. There is extra data prepended to the beginning of the hash:

0x150142b45efa15e7f4d24384ccf8e79cdd2c41eb6c2e5e14608020a2ab3b635f22988dbaa44590b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe2200

The additional data is 0x1501. Submitting this longer hash via the apps interface fails. Decoding the additional data shows me that it is equal to:

Decoding 0x1501: 
Uint8Array(1) [ 0 ]

This makes sense as I have an optional parameter in my contract function as follows:

const args = [arg1, arg2, undefined]

And the hex encoding of a null or undefined Option is:

console.log(new Option(env.network.registry, GenericAccountId, null).toU8a());
Uint8Array(1) [ 0 ]

If I exclude the optional parameter from my args I get an error about having too few arguments.

Error: Expected 3 arguments to contract message 'dapp_register', found 2
    at assert (/usr/src/app/node_modules/@polkadot/util/assert.cjs:36:11)
    at Abi.value (/usr/src/app/node_modules/@polkadot/api-contract/Abi/index.cjs:204:26)
    at Object.toU8a (/usr/src/app/node_modules/@polkadot/api-contract/Abi/index.cjs:163:102)
    at populateTransaction (/usr/src/app/node_modules/@redspot/patract/contract.js:30:27)
    at Object.dappRegister (/usr/src/app/node_modules/@redspot/patract/contract.js:57:16)
    at main (/usr/src/app/scripts/populateTxAndSign.ts:30:69)

How do I make sure I get the correct payload for submitting my contract transaction?

ii-ii-ii commented 2 years ago

Now polkadot dapp and ink both have a big upgrade. I'm not sure if this is the reason. Soon we will have a version compatible with these changes.