Use cases
The YAR protocol allows sending arbitrary transactions to any address, whether it's a smart contract or an EOA wallet.
Sending Transactions to an EOA Wallet
Such transactions usually only make sense when transferring the native token of the network, the amount of which is specified in the value parameter.
For example, a standard transaction within one network:
sender.sendTransaction({
from: sender.address, // sender
to: recipient.address, // recipient
value: 1e18, // amount of funds sent
})To deliver a similar transaction to another network, it looks like this:
yarRequest.send({
initialChainId,
sender: sender.address, // sender
payer: sender.address, // sender
targetChainId,
target: recipient.address, // recipient
value: 1e18, // amount of funds sent
data: '0x',
_nonce: 0,
})After executing this transaction, the Relayers network will transfer 1e18 of the target network's native tokens to the recipient's address.
Sending Transactions to a Smart Contract
Sending transactions to an arbitrary smart contract makes sense when the called method does not depend on the msg.sender address. For example, the address is passed in the arguments, or it involves meta-transactions or account abstraction.
For example, a standard transaction within one network:
To deliver a similar transaction to another network, it looks like this:
By executing this transaction, the YarResponse smart contract will parse the bytes from data and call the specified function at the target address. You can also pass the value parameter with this transaction if needed.
Here's the English translation of the provided Russian text, formatted for a programming context:
Cross-Chain API
The main potential of the Yar protocol lies in enabling communication between smart contracts of the same application located on different networks. Create an empty smart contract:
Register the addresses of [YarRequest] and [YarResponse] in the smart contract:
To send a cross-chain transaction from a smart contract, the [YarRequest] will require the data model [YarLib.YarTX].
Import YarLib into your smart contract:
Develop a receiver function that will accept a string of data. Two checks are required to identify the senders:
Check that
msg.senderequals theyarResponseaddress.Check that
yarTX.senderequals the address of your smart contract from the initial network.
Example of registering the addresses of your applications from external networks:
Now, to make this function callable from another network, implement a message-sending function.
Where message is the message to be sent
targetChainId is the network where the message will be delivered
returns(YarLib.YarTX) is used in simulation for gas estimation.
Encode the call to the [exampleReceiveMessage] function:
Then create YarTX:
or
Next, send this model to YarRequest:
Now, for the user to send a transaction from one of your smart contracts to another in an external network, they must have a balance in YarHub.
The balance can be topped up through YarRequest:
Next, grant permission to your application to spend funds:
Then, call your application:
The rest will be handled by the YAR network.
First, the deposit will be credited in YarHub:
Next, permission will be recorded for the transfer to the application:
Then, the user's transaction will be added to the queue:
After that, the transaction will be processed, temporarily locking sufficient funds on the user's deposit to complete the transaction:
Finally, the YAR network will deliver the transaction to the target network:
In the target network, the YarResponse smart contract will execute the transaction:
Last updated
Was this helpful?