Skip to Content
dApps
On this page

Sign and Send Transaction

Once a transaction is created, the web application may ask the user’s OneKey wallet to sign and send the transaction using their account’s private key and NEAR JSON RPC connection.

By far the easiest and recommended way of doing this is by using the requestSignTransactions method on the provider, but it is also possible to do with request.

In both cases, the call will return a Promise  for an object containing the transactionHashes.

requestSignTransactions()

// `transaction` is created in the Create Transaction guide. const res = await provider.requestSignTransactions({ transactions: [transaction], // must be Array type }); console.log('requestSignTransactions', res, res.transactionHashes);

request()

// `transaction` is created in the Create Transaction guide. const res = await provider.request({ method: 'near_sendTransactions', params: { transactions: [transaction], // must be Array type }, }); console.log('near_sendTransactions', res, res.transactionHashes);

Also transaction can be serialized to base64 string first before method calling.

// `transaction` is created in the Create Transaction guide. const transactionSerialized = btoa(String.fromCharCode(...transaction.encode())); const res = await provider.request({ method: 'near_sendTransactions', params: { transactions: [transactionSerialized], // must be Array type }, }); console.log('near_sendTransactions', res, res.transactionHashes);

Handle rejected requests in a try/catch block. A returned transaction hash is an identifier, not a guarantee of successful execution; check the transaction result through the network RPC.

Last updated on