call_chain_extension.sol 711 B

12345678910111213141516171819
  1. import "substrate";
  2. contract Foo {
  3. // Call the "rand-extension" example chain extension demonstrated here:
  4. // https://use.ink/macros-attributes/chain-extension
  5. //
  6. // This chain extension is registered under ID 1101.
  7. // It takes a bytes32 as input seed and returns a pseudo random bytes32.
  8. function fetch_random(bytes32 _seed) public returns (bytes32) {
  9. bytes input = abi.encode(_seed);
  10. (uint32 ret, bytes output) = chain_extension(1101, input);
  11. assert(ret == 0); // The fetch-random chain extension always returns 0
  12. bytes32 random = abi.decode(output, (bytes32));
  13. print("psuedo random bytes: {}".format(random));
  14. return random;
  15. }
  16. }