Skip to main content

Write data to blockchain

To put something in the Everscale blockchain, you need to send an external message to some account. Depending on a use-case and smart-contract logic, you may also want the account (usually it will be a users' Wallet smart-contract) to act as a proxy and forward your message to other contract. In this article, we describe both cases

Send External Message

// Encode the message with `touch` function call
const params = {
send_events: false,
message_encode_params: {
address,
abi,
call_set: {
function_name: 'touch',
input: {}
},
// There is no pubkey key check in the contract
// so we can leave it empty. Never use this approach in production
// because anyone can call this function
signer: { type: 'None' }
}
}
// Call `touch` function
let response = await client.processing.process_message(params);
console.log(`Сontract run transaction with output ${response.decoded.output}, ${response.transaction.id}`);

Encode and send Internal Message

  // Create Contract wrapper using ABI and an address
const example = new provider.Contract(contractABI, contractAddress);
// Send the external message `touch` to the contract
await example.methods.touch({}).send({
address: <Address object>, // you can get the address from AccountStorage, which is set up either manually or provided by the browser extension
amount: <nanotokens> // you should attach non-zero value of native currency to pay at least foraward, compute and storage fees of destination contract.
});
console.log('Message sent');

Explore the full guides to writing data to blockchain in Ever SDK here:

https://docs.everos.dev/ever-sdk/guides/work_with_contracts/deploy

https://docs.everos.dev/ever-sdk/guides/work_with_contracts/run_onchain

Advanced guide for working with Surf keeper provider is here.

If you use everscale-inpage-provider, see more docs and guides here:

https://docs.broxus.com