bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 10쪽
ub
(opens in a new tab)
ERC-4337 Safe SDK
Migrate to v2
Was this page helpful?
Report issue
## /sdk/relay-kit/guides/migrate-to-v2
SDK
Relay Kit
Guides
Migrate to v2
Migrate to v2
This guide references the major changes between v1 and v2 to help those migrating an existing app.
GelatoRelayPack
The
GelatoRelayPack
constructor now includes a mandatory
protocolKit
parameter. It's required for any new pack extending the
RelayKitBasePack
.
_
10
constructor({ apiKey, protocolKit }: GelatoOptions)
We removed the
protocolKit
parameter from the
createTransactionWithHandlePayment()
,
createTransactionWithTransfer()
, and
executeRelayTransaction()
methods in the
GelatoRelayPack
as now it's included in the constructor.
Removed the
export interface RelayPack
type as we now use an abstract class.
Gelato Relay (deprecated)
Migrate to v3
Was this page helpful?
Report issue
## /sdk/relay-kit/guides/migrate-to-v3
SDK
Relay Kit
Guides
Migrate to v3
Migrate to v3
This guide references the major changes between v2 and v3 to help those migrating an existing app.
Remove the adapters
We have removed the concept of adapters from the
protocol-kit
to simplify the library. Instead of using specific library adapters, we use now an internal
SafeProvider
object to interact with the Safe. This
SafeProvider
will be created using:
An Ethereum provider, an
EIP-1193
(opens in a new tab)
compatible provider, or an RPC URL.
An optional address of the signer that is connected to the provider or a private key. If not provided, the first account of the provider (
eth_accounts
) will be selected as the signer.
These changes affect the creation of the
Safe4337Pack
instance, as it was previously using an
ethAdapter
compatible object.
_
10
// old
_
10
const safe4337Pack = await Safe4337Pack.init({
_
10
ethAdapter: new EthersAdapter({ ethers, signerOrProvider }),
_
10
// ...
_
10
})
_
12
// new
_
12
const safe4337Pack = await Safe4337Pack.init({
_
12
provider: window.ethereum, // Or any compatible EIP-1193 provider,
_
12
signer: 'signerAddressOrPrivateKey', // Signer address or signer private key
_
12
// ...
_
12
})
_
12
_
12
const safe4337Pack = await Safe4337Pack.init({
_
12
provider: 'http://rpc.url', // Or websocket
_
12
signer: 'privateKey', // Signer private key
_
12
// ...
_
12
})
Migrate to v2
Migrate to V4
Was this page helpful?
Report issue
## /sdk/relay-kit/guides/migrate-to-v4
SDK
Relay Kit
Guides
Migrate to V4
Migrate to v4
This guide references the major changes between v3 and v4 to help those migrating an existing app.
FeeEstimator interface updated
The
IFeeEstimator
interface originally included three methods for users to hook into the process to estimate the fees of an User operation. In the
relay-kit
new version we simplified the interface to feature only two methods that configure or update the User operation fields before and after calling the standard RPC estimation method (
eth_estimateUserOperationGas
). Additionally, we renamed the methods to be more descriptive.
The old interface had this 3 methods:
setupEstimation
: This method enabled updating the gas related properties as needed before calling the
eth_estimateUserOperationGas
method.
adjustEstimation
: This method enabled to adjust the gas related properties as needed after calling the
eth_estimateUserOperationGas
method.
getPaymasterEstimation
: This method was called to retrieve and adjust the paymaster related fields if we want to use the
paymaster
feature. It was only called when the User operation were an sponsored one.
The new interface has only two methods:
preEstimateUserOperationGas
: This method enable developers to update the gas or paymaster fields before calling
eth_estimateUserOperationGas
.
postEstimateUserOperationGas
: This method enable to adjust the gas or paymaster fields as needed after calling the
eth_estimateUserOperationGas
.
With this new API, the user can have more control over the gas estimation process and enhance the flexibility of the User operation fields that can be updated after this call.
PimlicoCustomRpcSchema
only with Pimlico custom methods
We now have a separated
PimlicoCustomRpcSchema
that is used to define the custom RPC methods that are not part of the standard JSON-RPC methods. This schema is used to define the custom methods that are used in the
Pimlico
module. If you want to create your own estimator and call non-standard methods you should create your own one. Previously the
PimlicoCustomRpcSchema
included both the standard and custom methods.
The former
PimlicoCustomRpcSchema
is now
Safe4337RpcSchema
and includes only the standard JSON-RPC methods.
paymasterUrl
is now mandatory in
PaymasterOptions
Previously the
paymasterUrl
was only mandatory to work with sponsored User operations. Now it is mandatory to be set in the
PaymasterOptions
object as we are calling paymaster specific RPC methods (
pm_getPaymasterStubData
and
pm_getPaymasterData
) to fill the paymaster related fields.
Rename
addModulesLibAddress
We renamed the
addModulesLibAddress
method to
safeModulesSetupAddress
to reflect the change of the Safe contract name.
_
10
const safe4337Pack = await Safe4337Pack.init({
_
10
provider: window.ethereum, // Or any compatible EIP-1193 provider,
_
10
signer: 'signerAddressOrPrivateKey',
_
10
bundlerUrl: 'https://...',
_
10
customContracts: {
_
10
safeModulesSetupAddress: '0x1234567890123456789012345678901234567890' // Previously addModulesLibAddress
_
10
}
_
10
})
Renamed
EthSafeOperation
We renamed the
EthSafeOperation
to
BaseSafeOperation
so all the methods using it as a type in the
Safe4337Pack
will reflect this change
Migrate to v3
Safe4337Pack
Was this page helpful?
Report issue
## /sdk/relay-kit/reference/safe-4337-pack
SDK
Relay Kit
Reference
Safe4337Pack
Safe4337Pack
The
Safe4337Pack
enables Safe accounts to interact with user operations through the implementation of the
RelayKitBasePack
. You can find more about ERC-4337 at
this link
(opens in a new tab)
.
Install dependencies
To use
Safe4337Pack
in your project, start by installing the
relay-kit
package with this command:
_
10
yarn add @safe-global/relay-kit
Reference
The
Safe4337Pack
class make easy to use the
Safe 4337 Module
(opens in a new tab)
with your Safe. It enables creating, signing, and executing transactions grouped in user operations using a selected provider. You can select your preferred
bundler
(opens in a new tab)
and
paymaster
(opens in a new tab)
.
_
10
const safe4337Pack = await Safe4337Pack.init({
_
10
provider,
_
10
signer,
_
10
bundlerUrl,
_
10
safeModulesVersion,
_
10
customContracts,
_
10
options,
_
10
paymasterOptions
_
10
})
init(safe4337InitOptions)
The static method
init()
generates an instance of
Safe4337Pack
. Use this method to create the initial instance instead of the regular constructor.
ℹ️
We have added support for then Entrypoint v0.7 contract but we are not making it the default yet.
If you are using Entrypoint v0.7, you need to set the
safeModuleVersion
to
0.3.0
when calling the
Safe4337Pack.init
method. This version of the Safe 4337 Module is the one compatible with the Entrypoint v0.7.
Parameters
The
Safe4337InitOptions
used in the
init()
method are:
_
47
Safe4337InitOptions = {
_
47
provider: Eip1193Provider | HttpTransport | SocketTransport
_
47
signer?: HexAddress | PrivateKey | PasskeyArgType
_
47
bundlerUrl: string
_
47
safeModulesVersion?: string
_
47
customContracts?: {
_
47
entryPointAddress?: string
_
47
safe4337ModuleAddress?: string
_
47
addModulesLibAddress?: string
_
47
}
_
47
options: ExistingSafeOptions | PredictedSafeOptions
_
47
paymasterOptions?: PaymasterOptions
_
47
}
_
47
_
47
HexAddress = string
_
47
PrivateKey = string
_
47
HttpTransport = string
_
47
SocketTransport = string
_
47
_
47
Eip1193Provider = {
_
47
request: (args: RequestArguments) => Promise<unknown>
_
47
}
_
47
_
47
RequestArguments = {
_
47
method: string
_
47
params?: readonly unknown[] | object
_
47
}
_
47
_
47
ExistingSafeOptions = {
_
47
safeAddress: string
_
47
}
_
47
_
47
PredictedSafeOptions = {
_
47
owners: string[]
_
47
threshold: number
_
47
safeVersion?: SafeVersion
_
47
saltNonce?: string
_
47
}
_
47
_
47
PaymasterOptions = {
_
47
paymasterUrl?: string
_
47
isSponsored?: boolean
_
47
sponsorshipPolicyId?: string
_
47
paymasterAddress: string
_
47
paymasterTokenAddress?: string
_
47
amountToApprove?: bigint
_
47
}
provider
: The EIP-1193 compatible provider or RPC URL of the selected chain.
signer
: A passkey or the signer private key if the
provider
doesn't resolve to a signer account. If the
provider
resolves to multiple signer addresses, the
signer
property can be used to specify which account to connect, otherwise the first address returned will be used.
rpcUrl
: The RPC URL of the selected chain.
bundlerUrl
: The bundler's URL.
safeModulesVersion
: The version of the
Safe Modules contract
(opens in a new tab)
.
customContracts
: An object with custom contract addresses. This is optional, if no custom contracts are provided, default ones will be used.
entryPointAddress
: The address of the entry point. Defaults to the address returned by the
eth_supportedEntryPoints
method from the provider API.
safe4337ModuleAddress
: The address of the
Safe4337Module
. Defaults to
safe-modules-deployments
using the current version.
addModulesLibAddress
: The address of the
AddModulesLib
library. Defaults to
safe-modules-deployments
using the current version.
options
: The Safe account options.
safeAddress
: The Safe address. You can only use this prop to specify an existing Safe account.
owners
: The array with Safe owners.
threshold
: The Safe threshold. This is the number of owners required to sign and execute a transaction.
safeVersion
: The version of the
Safe contract
(opens in a new tab)
. Defaults to the current version.
saltNonce
: The Safe salt nonce. Changing this value enables the creation of different safe (predicted) addresses using the same configuration (
owners
,
threshold
, and
safeVersion
).
paymasterOptions
: The paymaster options.
paymasterUrl
: The paymaster URL. You can obtain the URL from the management dashboard of the selected services provider. This URL will be used for gas estimations.
isSponsored
: A boolean flag to indicate if we want to use a paymaster to sponsor transactions.
sponsorshipPolicyId
: The sponsorship policy ID can be obtained from the management dashboard of the selected payment services provider.
paymasterAddress
: The address of the paymaster contract to use.
paymasterTokenAddress
: The paymaster token address for transaction fee payments.
amountToApprove
: The
paymasterTokenAddress
amount to approve.
Returns
A promise that resolves to an instance of the
Safe4337Pack
.
Caveats
Use this method to create the initial instance instead of the standard constructor.
You should search for some API services URLs and contract addresses in the management dashboards of your selected provider. These include
bundlerUrl
,
paymasterUrl
,
paymasterAddress
,
paymasterTokenAddress
,
sponsorshipPolicyId
, and
rpcUrl
(In this case any valid RPC should be fine).
The SDK uses default versions when
safeModulesVersion
or
safeVersion
are not specified. You can find more details about the current versions
here
(opens in a new tab)
.
The
saltNonce
derives different Safe addresses by using the
protocol-kit
method
predictSafeAddress
. You can find more details about this process
here
(opens in a new tab)
.
We typically initialize the pack in two ways. One way is by using an existing account with the
safeAddress
prop. The other way is by using the
owners
,
threshold
,
saltNonce
, and
safeVersion
props to create a new Safe account. You can also apply the second method to existing addresses, as the output address will be the same if the inputs are identical.
The SDK queries
eth_supportedEntryPoints
for a default
entryPointAddress
if not given. It fetches
safe4337ModuleAddress
and
addModulesLibAddress
from the
safe-modules-deployments
repository if not provided. You can find them at:
safe-modules-deployments
(opens in a new tab)
.
To use a paymaster without sponsorship, you need to hold a certain amount of
paymasterTokenAddress
in the Safe account for fees. Make sure to provide the
paymasterAddress
as well.
You can choose to use a paymaster to sponsor transactions by setting the
isSponsored
prop. When sponsoring transactions, you need to provide the
paymasterUrl
,
paymasterAddress
, and optionally the
sponsorshipPolicyId
.
An approval for the concrete ERC-20 token is required to use the paymaster so remember to add the
paymasterTokenAddress
of the ERC-20 token that will pay the fees. The SDK will encode this approval internally and send it to the bundler with the rest of the user operation.
Specify the amount to approve for the
paymasterTokenAddress
using the
amountToApprove
prop. This is necessary when the Safe account is not deployed, and you need to approve the paymaster token for fee payments and Safe account setup.
new Safe4337Pack({protocolKit, bundlerClient, publicClient, bundlerUrl, paymasterOptions, entryPointAddress, safe4337ModuleAddress})
The
Safe4337Pack
constructor method is used within the
init()
method and should not be directly accessed. The parameters are calculated or provided by the
init()
method.
createTransaction(safe4337CreateTransactionProps)
Create a
SafeOperation
from a transaction batch. You can send multiple transactions to this method. The SDK internally bundles these transactions into a batch sent to the bundler as a
UserOperation
. If the transaction is only one then no batch is created a it's not necessary.
Parameters
The
Safe4337CreateTransactionProps
_
10
Safe4337CreateTransactionProps = {
_
10
transactions: MetaTransactionData[]
_
10
options?: {
_
10
amountToApprove?: bigint
_
10
validUntil?: number
_
10
validAfter?: number
_
10
feeEstimator?: IFeeEstimator
_
10
customNonce?: bigint
_
10
}
_
10
}
transactions
: Array of
MetaTransactionData
to batch in a
SafeOperation
(using the MultiSend contract if more than one transaction is included).
options
: Optional parameters.
amountToApprove
: The amount to approve to the
paymasterTokenAddress
.
validUntil
: The UserOperation will remain valid until this block's timestamp.
validAfter
: The UserOperation will be valid after this block's timestamp.
feeEstimator
: The fee estimator calculates gas requirements by implementing the
IFeeEstimator
interface.
customNonce
: The custom nonce for the SafeOperation. If not provided, the nonce will be calculated internally using the
getNonce
method from the Entrypoint contract.
Returns
A promise that resolves to the
SafeOperation
.
Caveats
The
SafeOperation
is similar to the standard user operation but includes Safe-specific fields. Before sending it to the bundler, we convert the
SafeOperation
to a regular user operation. We need to sign the operation for the bundler to execute it using the
Safe4337Module
.
You can set the
amountToApprove
in this method to approve the
paymasterTokenAddress
for transaction payments, similar to how
amountToApprove
works in the
init()
method.
We use a similar API to
protocol-kit
for developers transitioning to
Safe4337Pack
. This API helps with creating and executing transactions, bundling user operations and sending them to the bundler.
Use
validUntil
and
validAfter
to set the block timestamp range for the user operation's validity. The operation will be rejected if the block timestamp falls outside this range.
The
feeEstimator
calculates gas needs for the UserOperation. We default to
PimlicoFeeEstimator
, but the
relay-kit
package also offers an alternative,
GenericFeeEstimator
, which does not depend on any specific bundler. You can also provide your own estimator. The IFeeEstimator interface requires an object with specific methods.
User operations support the usage of
custom nonce
(opens in a new tab)
. You can use a custom nonce by leveraging the
createTransaction
method and passing the
customNonce
property as part of the
options
parameter. We exported an utility method
encodeNonce
in the
relay-kit
to make it easier to compose the nonce.
_
17
IFeeEstimator {
_
17
preEstimateUserOperationGas?: EstimateFeeFunction
_
17
postEstimateUserOperationGas?: EstimateFeeFunction
_
17
}
_
17
_
17
EstimateFeeFunctionProps = {
_
17
userOperation: UserOperation
_
17
bundlerUrl: string
_
17
entryPoint: string
_
17
}
_
17
_
17
EstimateSponsoredFeeFunctionProps = {
_
17
userOperation: UserOperation
_
17
paymasterUrl: string
_
17
entryPoint: string
_
17
sponsorshipPolicyId?: string
_
17
}
All methods are optional and will be called in the specified order if you provide any of them:
preEstimateUserOperationGas
: This method is used before calling the standard RPC
eth_estimateUserOperationGas
method, allowing you to setup the User operation before the bundler gas estimation.
postEstimateUserOperationGas
: This method is used after calling
eth_estimateUserOperationGas
method to adjust the bundler estimation.
signSafeOperation(safeOperation, signingMethod)
Signs a
SafeOperation
.
Parameters
safeOperation
: The
EthSafeOperation | SafeOperationResponse
to sign. Can either be created by the
Safe4337Pack
or fetched via
api-kit
.
signingMethod
: The method to use for signing the transaction. The default is
SigningMethod.ETH_SIGN_TYPED_DATA_V4
.
Returns
A promise that resolves to the signed
SafeOperation
.
Caveats
Use this method after the
SafeOperation
is generated with the
createTransaction
method.
This method adds the signer's signature to the signatures map of the
SafeOperation
object. Additional signatures can be included from multiple owners.
It works similar to
signTransaction
and
signMessage
methods in the
protocol-kit
but using
SafeOperation
instead of
SafeTransaction
or
SafeMessage
. For more information, refer to the Safe
docs
(opens in a new tab)
.
executeTransaction(safe4337ExecutableProps)
This method sends the user operation to the bundler.
ℹ️
If you are not using a paymaster and need to deploy a new Safe (counterfactual
deployment), you must hold in the predicted Safe address the amount of native
token required to cover the fees.
Parameters
The
Safe4337ExecutableProps
_
10
Safe4337ExecutableProps = {
_
10
executable: EthSafeOperation | SafeOperationResponse
_
10
}
executable
: The
SafeOperation
to execute. Can either be created by the
Safe4337Pack
or fetched via
api-kit
.
Returns
A promise, resolves to the user operation hash.
Caveats
The process converts the
SafeOperation
to a standard user operation, then forwards it to the bundler. The
SafeOperation
must be created and signed by the Safe owner.
You can use the user operation hash to browse the status (e.g
https://jiffyscan.xyz/userOpHash/{userOpHash}
)
getUserOperationByHash(userOpHash)
Retrieve the user operation using its hash.
Parameters
userOpHash
: The user operation hash is returned by the
executeTransaction
method. The user operation can be executed or pending, and the method will return the payload data for the user operation.
Returns
A Promise that resolves to
UserOperationWithPayload
.
_
10
UserOperationWithPayload = {
_
10
userOperation: UserOperation
_
10
entryPoint: string
_
10
transactionHash: string
_
10
blockHash: string
_
10
blockNumber: string
_
10
}
Caveats
Use this method to request information about the user operation sent to the bundler, but do not use it for the execution status.
getUserOperationReceipt(userOpHash)
Get
UserOperation
receipt by a hash.
Parameters
userOpHash
: Unique iden프로젝트로 돌아가기