0

I need to send a string of a digit and a letter like "2F" to a contract deployed on a running contracts node. This payload is to be processed in the contract then.

How can I include additional data to the transaction?
(I'm using Contracts UI node to send transactions)

1 Answer 1

0

The ink! docs state:

In general, you should think twice if you really need String. Smart contracts usually don't use strings; those are typically used for user interactions and should live in your UI and not on the chain.

You could use the @polkadot/api-contract and do the following:

const wsContractsProvider = new WsProvider('ws://localhost:9944');
const contractsApi = await ApiPromise.create({ provider: wsContractsProvider });
const address = "5EYtidretW1FmUjA6hisdq1AZ2GfsDUanDtSEuLghGzvdWau";
const contract = new ContractPromise(contractsApi, abi, address);

const value = 0; // only useful on isPayable messages
const gasLimit = -1;
const keyring = new Keyring({ type: 'sr25519' });
const alicePair = keyring.createFromUri("//Alice");

const value1 = 54;
const value2 = 88;

await contract.query.processSomething(alicePair.address, { value, gasLimit }, value1, value2);

In this case processSomething is an ink! message...:

/// Do some processing...
#[ink(message)]
pub fn process_something(&self, first: u32, second: u32) {
    ink_env::debug_println!("Do some processing... {}, {}", first, second);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.