Transactions are a formal action on a blockchain. They can be initiated in Sender with a call to NEAR's RPC node. They can be a simple sending of $NEAR, may result in sending fungible tokens, creating a new account, or changing state on the blockchain in any number of ways. They are always initiated by a signature from an NEAR account, usually with a function call key or full access key .
Sign and Send a Single Transaction
With Sender, you could sign and send a single transaction with one or multiple actions.
Copy // Call wNEAR contract method
// Register the 'xxx.testnet' account to wNEAR on testnet (wrap.testnet)
const tx = {
receiverId: 'wrap.testnet',
actions: [
{
methodName: 'storage_deposit',
args: {
account_id: 'alice.testnet',
registration_only: true,
},
gas: parseNearAmount('0.003'),
deposit: parseNearAmount('0.00125'),
},
],
}
const res = await window.near.signAndSendTransaction(tx);
Copy // Call multiple methods from wNEAR contract
// Swap NEAR to wNEAR, then transfer wNEAR to others
const tx = {
receiverId: 'wrap.testnet',
actions: [
{
methodName: 'near_deposit',
args: {},
deposit: parseNearAmount('1'),
},
{
methodName: 'storage_deposit',
args: {
account_id: 'bob.testnet',
registration_only: true,
},
gas: parseNearAmount('0.003'),
deposit: parseNearAmount('0.00125'),
},
{
methodName: 'ft_transfer',
args: {
received_id: 'bob.testnet',
amount: '1000000000000000000',
},
gas: parseNearAmount('0.003')
}
]
}
const res = await window.near.signAndSendTransaction(tx);
Sign and Send Multiple Transactions
Sender also supports sign and send multiple transactions when needed.
Copy const transactions = [
{
receiverId: wNearContractId,
actions: [
{
methodName: 'near_deposit',
args: {},
amount: '100000000000000000000000',
},
]
},
{
receiverId: RefFinanceContractId,
actions: [
{
methodName: 'add_liquidity',
args: {
tokens_ids: ['wrap.testnet', 'token.paras.testnet'],
amounts: ['1000000000000000000', '1000000000000000000'],
},
}
]
}
];
const res = await window.near.requestSignTransactions({ transactions });
console.log('Swap and Send wNEAR with requestSignTransactions response: ', res);