Steps
- In order to send your first transaction, you’ll first need to fund your wallet. You can get some test MON tokens by using the Client API Fund Wallet endpoint.
- Next, we’ll need to format a transaction object.
- Now that we some testnet ETH, let’s send a transaction! We will send our test funds to a Portal test wallet using a single API request to
https://mpc-client.portalhq.io/v1/sign.- You can learn more about Ethereum transactions here, but for this example you only need to know about a few fields:
method: this defines which Ethereum RPC signer method we want to use.params: these are the parameters of your transaction.value: this is the amount of MON measured in wei and hex encoded.from: this is the address of the sender - your wallet in this case.to: this is the address you’re sending to - our test wallet in this case.data: this is used for interacting with smart contracts - we can ignore it.
- You can learn more about Ethereum transactions here, but for this example you only need to know about a few fields:
eth_sendTransaction Ethereum RPC method to instruct the Portal API to both sign and submit a transaction to the blockchain.
If your wallet is not funded, you will receive a RPC error on this step.
Sign a user operation without submitting it
If your client uses Account Abstraction,eth_sendTransaction builds, signs and submits an ERC-4337 user operation for you in one call. Use eth_signUserOperation when you want Portal to build and sign the user operation but submit it to a bundler yourself.
You do not build the user operation. You send a transaction, and Portal returns the signed user operation made from it. To batch several calls into one user operation, or to have Portal submit it for you, use Build, sign and broadcast a user operation instead.
Steps
- Call
/v1/signwithmethodset toeth_signUserOperation.paramsis the same transaction you would pass toeth_sendTransaction, as a JSON object or a JSON-encoded string:
- The response
datais the signed user operation, encoded as hex of its JSON:
- Decode it back to JSON:
- Submit the decoded user operation, unchanged, to an ERC-4337 bundler (Portal’s RPC endpoint does not accept
eth_sendUserOperationfor these operations yet) witheth_sendUserOperationand the EntryPoint v0.6 address0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789. For example, with Pimlico:
- Poll the bundler with
eth_getUserOperationReceiptand that hash until it returns a result.successtells you whether the call inside the user operation succeeded, andreceipt.transactionHashis the on-chain transaction:
Things to know
- Every field is covered by the signature, so any change, including gas fees, invalidates it. Call
eth_signUserOperationagain instead of editing the result. A bundler whose minimum fees are higher than the ones Portal priced will reject the user operation. signaturealready carries the 4 leading zero bytes the smart account expects.initCodeis set until the smart account is deployed. The first user operation you submit deploys it.- Gas is sponsored by default when your environment has gas sponsorship configured for the chain. To opt out, pass
"sponsorGas": falseat the top level of the request body (next tomethod, not insideparams);paymasterAndDatathen comes back empty and the smart account pays for gas. - When the smart account pays its own gas, EntryPoint v0.6 takes the maximum possible gas cost up front and refunds the unused part to the account’s EntryPoint deposit (
balanceOf(sender)on the EntryPoint), not its native balance. The deposit is used toward the next user operation’s gas. - If sponsorship is not available for an operation, the call still succeeds and
paymasterAndDatacomes back empty. Check it before submitting: with no paymaster, the smart account must hold enough native token to pay for gas, or the bundler rejects the operation withAA21 didn't pay prefund. - Paymaster data on a sponsored user operation is only valid for a short time (about 10 minutes), so submit it soon after signing.
eth_signUserOperationonly works for Account Abstraction clients. Other clients get a 400 withMETHOD_UNSUPPORTED.
Build, sign and broadcast a user operation
Use this flow when you want to batch several calls into one ERC-4337 user operation, or to see the user operation and its gas estimate before signing it. To control every field of the user operation yourself, see Sign a user operation you built. Portal builds the user operation, you sign its hash with the Enclave MPC API, and Portal submits it to the bundler. You do not need a bundler of your own. It works for Account Abstraction clients only.Steps
- Build the user operation with the Client API build user operation endpoint. Each entry in
callsis one call the smart account makes, in order:
estimatedGasCostWei is the most the user operation can cost when the smart account pays for its own gas:
- Sign
userOpHashwith the raw signing endpoint, without the0xprefix:
data is the signature.
- Broadcast the user operation with the Client API broadcast user operation endpoint. Pass
userOperationexactly as the build step returned it, and the signature exactly as the raw signing endpoint returned it. Portal formats the signature for the smart account and submits the user operation to the bundler:
- Look up the user operation hash with get transaction (
GET /api/v3/clients/me/chains/{chain}/transactions/{hash}). The on-chain transaction hash appears once a bundler includes the user operation, usually within a few seconds; until then the lookup returns 404.
Things to know
- Sign and broadcast soon after building. The user operation carries the gas prices and nonce from the moment it was built, and a sponsored one carries paymaster data that expires after a few minutes.
- The build step runs your environment’s transaction policies on every call, and returns 403 with
policyViolationwhen one blocks it. - Gas is sponsored when your environment has gas sponsorship configured for the chain. If
paymasterAndDatain the built user operation is0x, the smart account pays for gas and needs enough native token to coverestimatedGasCostWei. - Clients without Account Abstraction get a 400:
Account Abstraction is not enabled, contact support to enable it.
Sign a user operation you built
Use this flow when you build the user operation yourself, for example to use your own paymaster, gas settings or calldata encoding. Portal only signs its hash. You can then submit it through Portal or to your own bundler. The user operation has to match the smart account Portal created for the client:Steps
- Compute the EntryPoint v0.6 user operation hash, for example with viem:
- Sign
userOpHashwith the raw signing endpoint, without the0xprefix:
data is a 65-byte signature: r, s, then a recovery id of 00 or 01.
-
Submit the user operation one of two ways:
- Through Portal: call broadcast user operation with your user operation as
userOperationand the signature exactly as the raw signing endpoint returned it. Portal formats the signature for the smart account and submits it. - To your own bundler: format the signature for the Kernel smart account first, then call
eth_sendUserOperation:
- Through Portal: call broadcast user operation with your user operation as
0x00000000 prefix selects the Kernel smart account’s default validator. A signature without it, or with a v of 00/01, fails validation at the bundler.
- Confirm inclusion with get transaction for the user operation hash, or with your bundler’s
eth_getUserOperationReceipt.