Skip to main content
9 votes
Accepted

Using Scheduler Pallet to schedule Contract pallet call

Alright, so I had a chat with Kian about this and he gave me some tips for how to approach this. First, we need to distinguish between Runtime Calls and Pallet Calls. The Runtime calls are those that ...
HCastano's user avatar
  • 1,071
7 votes
Accepted

Correct way to use dynamic sized types in chain extension

In order to read memory from a contract you should check out the different functions on the Environment type. As Green Baneling already pointed out correctly you should use SCALE in order to encode ...
Alexander Theißen's user avatar
7 votes
Accepted

How can I pass a Vec<u8> via chain extension to pallet?

You can only use read_as() for types whose size is known at compile time (thus the requirement that types implement MaxEncodedLen). If you don't know the size ahead of time, like in the case of a Vec, ...
HCastano's user avatar
  • 1,071
6 votes

Error when compiling a contract using the XCM chain extension

The xcm crate at some point imports the sp-io that contains its own implementation of the allocator making conflicts with the global_allocator of ink! This can be solved importing the sp-io as well ...
Hector Bulgarini's user avatar
5 votes
Accepted

How do I test a chain extension used in the runtime?

I'm not sure if this is the simplest way, but I came up with a solution. Write a basic smart contract that calls each chain extension function Create a mock runtime using the chain extension Write a ...
ExplodingJay's user avatar
4 votes
Accepted

Chain Extension func_id enumeration is resulting in ContractTrapped for func ids greater than 1

I figured it out. I had not added the additional function ids to the FromStatusCode implementation. After updating it to the below, it works as intended. impl ink_env::chain_extension::FromStatusCode ...
Tony's user avatar
  • 527
4 votes

How to return error from chain extension?

You need to SCALE encode the Result([u8; 16], SomeError) and write it to the output buffer: impl ChainExtension for MyExtension { fn call(func_id: u32, env: Environment) -> Result<RetVal> ...
Alexander Theißen's user avatar
3 votes

How do I test a chain extension used in the runtime?

There doesn't seem to be a clear way to test that e.g. a given call function in a chain extension is set up to behave the way that is expected(because it's difficult to instantiate the Environment ...
Justin Frevert's user avatar
3 votes
Accepted

Is it possible to integrate a third-party library into a smart contract using ink!

You can treat ink! contract as any other rust application - you can add dependencies to your Cargo.toml file and use these dependencies across your project, however, these libraries need to enable ...
kriko.eth's user avatar
  • 764
3 votes

How to receive multiple parameters of different types in chain extension

Pierre is right, your arguments need to be encodeable/decodeable (T: Encode + Decode). By doing this you'll be able to use the read_as method in your chain extension implementation which will try and ...
HCastano's user avatar
  • 1,071
3 votes

How to receive multiple parameters of different types in chain extension

All your args will be passed as a SCALE encoded message param. That's why on the runtime you should decode it using a struct that derive Scale Encode + Decode + MaxEncodedLen and have the exact same ...
P.Ossun's user avatar
  • 1,219
2 votes

Correct way to use dynamic sized types in chain extension

Each type in ink! implements scale::Encode and scale::Decode. That serialization and deserialization are used across the substrate everywhere. To pass some dynamic types you can encode it on the ...
Green Baneling's user avatar
1 vote
Accepted

Pallet extrinsic event not triggering when called through chain extension

The problem was fixed by changing the parameter in the build method to 0x10001. The indexes of the chain extension and function id were not correct.
Snowmead's user avatar
  • 625
1 vote

In the runtime chain extension, should we be charging weight if we are reading a `StorageMap`?

If you are not doing complex calculations in your runtime, most of the time the storage reading/writing should dominate your weight. With 2D weights which also include the increase of the proof size, ...
bkchr's user avatar
  • 11.5k
1 vote
Accepted

Charge weight and weight Info in chain-extension

I wonder if you should charge weight before any call to the pallet: You need to charge manually as demonstrated in your example. It is only automatically charged when the Call is included in an ...
Alexander Theißen's user avatar
1 vote

Cannot upgrade contract using chain extension

Two things would be helpful for giving a specific answer: Can you update your reproducer code to ink! 4.0? We have a migration guide here. There were some fixes along the way and I just want to ...
cmichi's user avatar
  • 2,800
1 vote

Access to chain extension method from another module in ink!

It is currently not possible to reference the chain extension method from a different file. It's good that you raised this and I just created this issue for it: https://github.com/paritytech/ink/...
cmichi's user avatar
  • 2,800
1 vote

How ink! handles DispatchError from ChainExtension

The question is What is the appropriate way for ink! smart contract messages to handle DispatchError (from ChainExtension) and return it as its returned value? How I understand your question is that ...
cmichi's user avatar
  • 2,800
1 vote

How to benchmark a chain extension?

The benchmark docs are the best place to start, and good examples of benchman.rs files in Substrate as reference. Your goal is to create worst case scenario weights for using your chain extension, as ...
Nuke's user avatar
  • 1,842
1 vote
Accepted

Contract CodeRejected when using chain extension

You forgot to tell pallet-contracts about your chain extensions here. You need to do this: type ChainExtension = IrisExtension;
Alexander Theißen's user avatar
1 vote

How to retrieve dynamic type size data from chain extension in ink?

As the error suggests, the size has to be known at compilation time. So, either sized arrays, or ink_prelude::vec::Vec is what you need.
kriko.eth's user avatar
  • 764

Only top scored, non community-wiki answers of a minimum length are eligible