Skip to main content
5 votes
Accepted

Generate random number ink!

The Keccak256 hash algorithm produces a 256-bit (32-byte) hash, and its associated type Type is [u8; 32]. In your code you always take just output[0] of type u8 and your result is always less than u8::...
Maario's user avatar
  • 659
5 votes
Accepted

Get contract address from instantiated ContractRef

You can use to_account_id method to obtain address of instantiated smart contract. use ink::ToAccountId; let contract_address = multisig.to_account_id();
Bobo K.'s user avatar
  • 386
4 votes

What type should an ink! contract use to store a `uint256` block number retrieved from a Solidity contract?

In ink! you can use self.env().block_number() or Self::env().block_number() in the constructor. If you want to use XVM (only available in Shibuya) and query an solidity contract, you can deploy a ...
P.Ossun's user avatar
  • 1,219
4 votes
Accepted

Usage of XVM in ink! smart contract

There is no way at the moment to do ink! cross-chain contract. Astar & Parity are actively working on this. In the meantime this is Astar roadmap regarding ink! XCM:
P.Ossun's user avatar
  • 1,219
3 votes

What is the purpose of installing cargo-contract and using it to create Ink! Rust smart contracts?

To develop Ink! smart contracts using Rust, you need to install the cargo-contract tool. cargo-contract is a Cargo subcommand specifically designed for developing smart contracts on the Substrate ...
Arunjot Singh's user avatar
3 votes

Error while trying to run e2e rust ink! tests

Whenever you see this macro #![feature(min_specialization)] in the error message it is most likely that you are not using rust nightly. This macro is not supported by the stable rust version and you ...
Maario's user avatar
  • 659
3 votes
Accepted

How to stub ink! contract environment to produce fake values for use in tests?

There is advance_block function in the ink::env::test and you can do something like this: fn advance_n_blocks(n: u32) { for _ in 0..n { advance_block(); } } fn advance_block() { ...
Maario's user avatar
  • 659
3 votes
Accepted

Cross-Contract Calls and Events don't work (ink 4.2.1)

Why don't you do exactly what error message states? Replace self.env().emit_event(FakeEvent { account_id: caller }); with use ink::{ codegen::EmitEvent, env::DefaultEnvironment, EnvAccess, }; &...
Bobo K.'s user avatar
  • 386
3 votes
Accepted

Call ink! smart contracts from hardware devices that use embedded rust

Have a look at subxt (submit extrinsics to a substrate node via RPC using only Rust) There is some extended test that you can reuse to call contracts: Have a look HERE
P.Ossun's user avatar
  • 1,219
3 votes
Accepted

How can I check the balance of the account in ink smart contract

Some previous answers that might be useful for you : How can I determine the native Balance of an Account/Address in Ink! How can I call my pallets and it functions in a smart contract? How to call ...
dominique's user avatar
  • 1,683
3 votes
Accepted

Contract Trapped on Single Message

Just from a quick look at the code, I think the problem might be you are calling self.env().transfer() two times, and contract is trapped because it fails on expect instead of returning a specific ...
kriko.eth's user avatar
  • 764
3 votes
Accepted

How do set the appropriate refTime and proofSize when create asMulti?

You can create your asMulti call with some default values for reftime and proofsize. An example would be to set at your new weight the same RefTime as found in your old weight and for proofsize a ...
dominique's user avatar
  • 1,683
3 votes
Accepted

Are web3.js & ethers.js compatible with ink! smart contracts?

No, the underlying RPC-based communication is not the same. There is an interesting discussion in the Polkadot Forum you might want to follow: WrappedEVM Eth RPC compatibility layer. The alternative ...
Alex Bean's user avatar
  • 5,747
2 votes

How to filter the subscribed contracts events with their topics?

You can use useink and the hook useEvents, which will subscribe to a contract's events. Here is an example using it and decoding the events that are emitted.
Sam Ruberti's user avatar
2 votes

What is the purpose of installing cargo-contract and using it to create Ink! Rust smart contracts?

To understand the role of cargo-contract in developing Ink! smart contracts, let's break it down: Cargo: Cargo is the build system and package manager for Rust. It simplifies the process of managing ...
the dev's user avatar
  • 477
2 votes

How do I upgrade an ink contract with storage changes?

You should not change the layout of the storage after upgrade. The order and types of the fields has to remain the same. If you want to remove the field a, you can simply rename it to c as the order ...
kriko.eth's user avatar
  • 764
2 votes

Getting OutOfGas Error when trying to call smart contract

Looking at the code you provided, couple of things needs to be modified: The line const gasRequired = preview.gasRequired as WeightV2 should probably be const gasRequired = result.gasRequired as ...
codespool's user avatar
  • 156
2 votes

Getting "Contract Reverted!" error with "TooManyTopics" dispatch error when calling mint function in OpenBrush PSP37 smart contract

When encountering the "Contract Reverted!" error with the "TooManyTopics" dispatch error while calling the mint function in the OpenBrush PSP37 smart contract, it is likely due to ...
the dev's user avatar
  • 477
2 votes

Generating random numbers in ink!

I think ink_env, no longer provides support for random: https://docs.rs/ink_env/4.3.0/ink_env/#functions What should be used for the moment?
munificent's user avatar
2 votes

How to call PSP22::approve function from Frontend

The way I approach such error is in 2 steps. Make sure contract works. Use Contracts-UI, deploy the contract and check that approve/allowance work as you expected. Dry-run Tx Before sending Tx, ...
Maario's user avatar
  • 659
2 votes
Accepted

block time_stamp return value

The value 1,690,534,220,344 is a Unix timestamp when the block is produced. If you are unaware of unix timestamp below is the definition. The number of seconds that have elapsed since January 1, 1970, ...
Immanuel John's user avatar
2 votes
Accepted

Calculate how many days

Below is the general calculation for finding the days. // Calculate the time difference between unstaking and staking timestamps. let time_difference = unstaking_timestamp .checked_sub(...
Immanuel John's user avatar
2 votes
Accepted

Writing Unit Tests

The scenario you are described can not be covered by an unit test. Unit tests are intended for testing one piece (unit, class) of code, e.g. single smart contract. If you want to test interaction ...
Bobo K.'s user avatar
  • 386
2 votes

How to get and modify cross-chain asset in contract?

Those are two different things, 1. Interacting with Local USDT Asset (4294969280) on Astar If you want to interact with pallet-assets assets like USDT, you can use ink! Chain Extension. We have the ...
Ashutosh Varma's user avatar
2 votes
Accepted

Error in deploying call_runtime contract from ink!

The error above is most likely because contracts pallet on Aleph Zero is not configured to support call_runtime. Aleph Zero configuration impl pallet_contracts::Config for Runtime { type Time = ...
Bobo K.'s user avatar
  • 386
2 votes
Accepted

What is a Storage Deposit?

The storage deposit is the payment for the contract storage. https://github.com/paritytech/substrate/blob/0cdf7029017b70b7c83c21a4dc0aa1020e7914f6/frame/contracts/primitives/src/lib.rs#L57-L63 It is ...
Bruno's user avatar
  • 8,315
2 votes

In what scenarios should we use a pallet to call an ink! smart contract?

First, in any case you need a pallet to call a smart contract (SC). Pallet-contracts and pallet-evm provide the functionality to call a WASM SC or Solidity SC respectively. There can be many reasons ...
Daan van der Plas's user avatar
2 votes
Accepted

How to restrict ink! contracts code upgrade?

I believe the recommended approach in your case because you only want to disable a call is to customize the BaseCalleFilter (In pallet_contract Config) to filter out the calls you want to execute. ...
Alex Bean's user avatar
  • 5,747
2 votes
Accepted

How can I send a native token from a contract to an externally owned account in an ink smart contract?

By using transfer. See example here self.env() .transfer(recipient, amount) .map_err(|_| Error::TrasnferError)?;
P.Ossun's user avatar
  • 1,219
2 votes

is there any ways to automatically trigger ink smart contract based on certain conditions?

There is no way to automate smart contract functions solely from within a smart contract. The smart contract requires a transaction that supplies it with gas (CPU Time / Storage fees), which allows it ...
forgetso's user avatar
  • 1,514

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