Взаимодействие со смарт-контрактом Ink
Сначала мы поместим код смарт-контракта в блокчейн с помощью
const result = await api.tx.contracts.putCode(bytes).signAndSend(pair)
тогда мы создадим контракт с
const instantiate = await api.tx.contracts.instantiate(0, 500000, result, abi.constructors[0]).signAndSend(pair)
Как мы устанавливаем значение init, вызываем get и вызываем метод flip следующего контракта с polkadot js?
mod flipper {
use ink_core::storage;
/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[ink(storage)]
struct Flipper {
/// Stores a single `bool` value on the storage.
value: storage::Value<bool>,
}
impl Flipper {
/// Constructor that initializes the `bool` value to the given `init_value`.
#[ink(constructor)]
fn new(&mut self, init_value: bool) {
self.value.set(init_value);
}
/// Constructor that initializes the `bool` value to `false`.
///
/// Constructors can delegate to other constructors.
#[ink(constructor)]
fn default(&mut self) {
self.new(false)
}
/// A message that can be called on instantiated contracts.
/// This one flips the value of the stored `bool` from `true`
/// to `false` and vice versa.
#[ink(message)]
fn flip(&mut self) {
*self.value = !self.get();
}
/// Simply returns the current value of our `bool`.
#[ink(message)]
fn get(&self) -> bool {
*self.value
}
}
}