Skip to main content

Signing

The Portal instance includes a number of helper functions to allow you to execute Provider requests without having to worry about encoding, request format, or what method to pass in your request. These helper functions allows you to easily sign and submit transactions, sign messages, and even sign typed data.
const chainId = 'eip155:1' // Ethereum Mainnet
const myAddress = await portal.getEip155Address() // Your Ethereum address
const messageToSign = "0x48656c6c6f20576f726c64" // Message must be a hex string

const signature = await portal.request({
    chainId,
    method: 'eth_sign',
    params: [myAddress, messageToSign],
    signatureApprovalMemo: 'Optional memo shown during approval', // optional
})

Signature approval memo

Clients can pass an optional signatureApprovalMemo so the user sees a short description during the approval flow. It is supported in:
  • portal.request() — add signatureApprovalMemo to any signing method (eth_sendTransaction, personal_sign, sol_signAndSendTransaction, etc.).
  • portal.sendAsset(chain, params) — include signatureApprovalMemo in the params object. See Send tokens.
  • portal.rawSign(curve, param, options) — pass an optional third argument with the memo.
Example: request with memo
const txHash = await portal.request({
  chainId: 'eip155:1',
  method: 'eth_sendTransaction',
  params: [transaction],
  signatureApprovalMemo: 'Send transaction',
})
Example: rawSign with memo
const signature = await portal.rawSign(
  PortalCurve.SECP256K1,
  messageHex,
  { signatureApprovalMemo: 'Sign login challenge' }
)

Raw Requests with the Provider

Estimating Gas

By default, Portal will estimate and populate the gas property in a transaction object if the property is undefined. To estimate the gas value manually use the eth_estimateGas RPC call and pass in your transaction as the parameter.
const gas = await portal.request({
    chainId: 'eip155:1',
    method: 'eth_estimateGas',
    params: [
        // partial transaction to estimate gas for
        {
            from:"0xFROMADDRESS",
            to:"0xTOADDRESS",
            value:"0xVALUE",
            input:"HASH_OF_CONTRACT_CALL_DATA", // only needed if calling a smart contract
        }
    ]
})

console.log(gas)
// "0x5208"
And now you are signing transactions with Portal! 🙌 🚀 Next, we’ll explore how to simulate a transaction so that you can create smoother experiences for your users.