Safe 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 12쪽

ready, authenticated } = usePrivy() _ 10 const { ready: readyWallets, wallets } = useWallets() Login To login with an email address or social account you need to call the following method, that will open the popup and request the user to submit the login form. _ 10 login() Get the provider and signer Once the user is logged in, you can get the provider and signer , which is the externally-owned account of the user that was derived from its credentials. To do that there is a useEffect() that is executed when any of the ready , authenticated , readyWallets and wallets variables have its value updated. Once they all are true and wallets has a length greater than zero, you have access to the wallets first element, which is the user's connected signer. viem You can instantiate the provider using viem and the following imports: _ 10 import { createWalletClient, custom } from 'viem' _ 10 import { sepolia } from 'viem/chains' _ 15 useEffect(() => { _ 15 const init = async () => { _ 15 if (ready && authenticated && readyWallets && wallets.length > 0 ) { _ 15 const ethereumProvider = await wallets[0].getEthereumProvider() _ 15 _ 15 const provider = createWalletClient({ _ 15 chain: sepolia, _ 15 transport: custom(ethereumProvider) _ 15 }) _ 15 _ 15 const signer = wallets[0].address _ 15 } _ 15 } _ 15 init() _ 15 }, [ready, authenticated, readyWallets, wallets]) With the provider and signer you are ready to instantiate any of the kits from the Safe{Core} SDK and set up or use this signer as a Safe owner. Logout Finally, to logout the user, call the logout() method. _ 10 logout() Recap and further reading After following this guide, you are able to create a Safe signer using Privy and get the provider and signer required to initialize the kits from the Safe{Core} SDK. Learn more about Privy by checking the following resources: Privy website (opens in a new tab) Privy documentation (opens in a new tab) Privy quickstart guide (opens in a new tab) Passkeys Web3Auth Was this page helpful? Report issue ## /sdk/signers/web3auth SDK Signers Web3Auth Web3Auth Signer In this guide, you will learn how to create a Web3Auth (opens in a new tab) signer that can be added as a Safe owner and used to initialize any of the kits from the Safe{Core} SDK. Check out the Safe Signers demo app (opens in a new tab) on GitHub to follow along this guide with the completed code. Prerequisites Node.js and npm (opens in a new tab) . A Web3Auth account (opens in a new tab) and a Client ID. Install dependencies npm yarn pnpm _ 10 npm install @web3auth/modal @web3auth/base @web3auth/ethereum-provider Steps Imports Here are the necessary imports for this guide. _ 10 import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } from '@web3auth/base' _ 10 import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider' _ 10 import { Web3Auth } from '@web3auth/modal' In addition, you will need to import a web3 library of your choice to use in the "Get the provider and signer" section. In this guide, we are using viem . Get the Client ID Check Web3Auth documentation on how to create a new project in their dashboard (opens in a new tab) and get the client ID (opens in a new tab) . Once you have it, you need to initialize the WEB3AUTH_CLIENT_ID variable with it. _ 10 const WEB3AUTH_CLIENT_ID = // ... Initialize Web3Auth Web3Auth initialization is done by instantiating the Web3Auth class with a clientId , a privateKeyProvider and some other configuration parameters like web3AuthNetwork , depending on if you are using it in a development or production environment. The full list of parameters can be checked in the Instantiating Web3Auth guide (opens in a new tab) from Web3Auth. To instantiate the privateKeyProvider you need to define the configuration of the selected chain for the signer with several properties like the ones listed below as an example for Sepolia testnet. After initializing the web3auth instance, you need to call the initModal() method. _ 22 const chainConfig = { _ 22 chainNamespace: CHAIN_NAMESPACES.EIP155, _ 22 chainId: '0xaa36a7', _ 22 rpcTarget: 'https://ethereum-sepolia-rpc.publicnode.com', _ 22 displayName: 'Ethereum Sepolia Testnet', _ 22 blockExplorerUrl: 'https://sepolia.etherscan.io', _ 22 ticker: 'ETH', _ 22 tickerName: 'Ethereum', _ 22 logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png' _ 22 } _ 22 _ 22 const privateKeyProvider = new EthereumPrivateKeyProvider({ _ 22 config: { chainConfig } _ 22 }) _ 22 _ 22 const web3auth = new Web3Auth({ _ 22 clientId: WEB3AUTH_CLIENT_ID, _ 22 privateKeyProvider, _ 22 web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET _ 22 }) _ 22 _ 22 await web3auth.initModal() Login To login with an email address or social account you need to call the following method, that will open the popup and request the user to submit the login form. _ 10 const web3authProvider = await web3auth.connect() Get the provider and signer Once the user is logged in, you can get the provider and signer , which is the externally-owned account of the user that was derived from its credentials. viem You can instantiate the provider using viem and the following imports: _ 10 import { createWalletClient, custom } from 'viem' _ 10 import { sepolia } from 'viem/chains' _ 10 const provider = createWalletClient({ _ 10 chain: sepolia, _ 10 transport: custom(web3authProvider) _ 10 }) _ 10 _ 10 const signer = await provider.getAddresses())[0] With the provider and signer you are ready to instantiate any of the kits from the Safe{Core} SDK and set up or use this signer as a Safe owner. Logout Finally, to logout the user, call the logout() method. _ 10 await web3auth.logout() Recap and further reading After following this guide, you are able to create a Safe signer using Web3Auth and get the provider and signer required to initialize the kits from the Safe{Core} SDK. Learn more about Web3Auth by checking the following resources: Web3Auth website (opens in a new tab) Web3Auth documentation (opens in a new tab) Web3Auth quickstart guide (opens in a new tab) Privy On-chain Tracking Was this page helpful? Report issue ## /sdk/onchain-tracking SDK On-chain Tracking On-chain Tracking We aim to understand better and recognise our key contributors who are driving the adoption of smart accounts within our ecosystem. Implementing a Safe on-chain identifier enables tracking of complex data, such as whether a Safe transaction is executed via our SDK or another, whether it originates from a platform like a Safe App or widget (for example, the CoW Swap widget in our Safe interface), the tool version, the project, and more. By submitting your on-chain identifier through the form provided at the end of this page, you will help us accurately attribute activity and allow us to return value to our Ecosystem Partners in the future. ℹ️ On-chain tracking is supported starting from Protocol Kit v5.2.0 and Relay Kit v3.4.0 . On-chain identifier format The identifiers used to track Safe deployments and transactions are 50 bytes in length and follow the format below: 5afe 00 6363643438383836663461336661366162653539 646561 393238 653366 Check the last 50 bytes of the data field in this example transaction (opens in a new tab) to see how the identifier appears after the transaction is executed. Prefix hash Type: 2 bytes Example: 5afe Static prefix to identify the Safe on-chain identifier. Version hash Type: 1 byte Example: 00 Version number of the Safe on-chain identifier format. Project hash Type: 20 bytes Example: 6363643438383836663461336661366162653539 Truncated hash of the project's name (for example, "Gnosis", "CoW Swap"). Platform hash Type: 3 bytes Example: 646561 Truncated hash of the platform's name (for example, "Web", "Mobile", "Safe App", "Widget"). Tool hash Type: 3 bytes Example: 393238 Truncated hash of the tool's name (for example, "protocol-kit", "relay-kit", or any custom tool built by projects). Tool version hash Type: 3 bytes Example: 653366 Truncated hash of the tool's version (for example, "1.0.0", "1.0.1"). Steps The on-chain identifier allows tracking the deployment of Safe accounts, the execution of Safe transactions, and the execution of Safe user operations: Generate an on-chain identifier Feel free to skip this section if you use the Protocol Kit or Relay Kit from the Safe{Core} SDK, as this is handled internally. To create an on-chain identifier with the format described above, you need to implement a function that receives the project , platform , tool , and toolVersion used; and returns the correct identifier after hashing, truncating, and concatenating all these parameters. _ 20 function generateOnChainIdentifier({ _ 20 project, _ 20 platform = 'Web', _ 20 tool, _ 20 toolVersion _ 20 }: OnChainIdentifierParamsType): string { _ 20 const identifierPrefix = '5afe' // Safe identifier prefix _ 20 const identifierVersion = '00' // First version _ 20 const projectHash = generateHash(project, 20) // Take the last 20 bytes _ 20 const platformHash = generateHash(platform, 3) // Take the last 3 bytes _ 20 const toolHash = generateHash(tool, 3) // Take the last 3 bytes _ 20 const toolVersionHash = generateHash(toolVersion, 3) // Take the last 3 bytes _ 20 _ 20 return `${identifierPrefix}${identifierVersion}${projectHash}${platformHash}${toolHash}${toolVersionHash}` _ 20 } _ 20 _ 20 function generateHash(input: string, size: number): string { _ 20 const fullHash = keccak256(toHex(input)) _ 20 return toHex(fullHash.slice(-size)).replace('0x', '') // Take the last X bytes _ 20 } This identifier will be added to all your Safe transactions and become searchable on-chain. Track Safe deployments Safe deployments can be tracked by concatenating the on-chain identifier at the end of the deployment transaction data . This way Safe deployment transactions will include the identifier. If you use the Protocol Kit or the Relay Kit to deploy a Safe, adding the onchainAnalytics property to the initialization method will automatically handle this. If you use a custom implementation, remember to manually add the on-chain identifier at the end of the deployment transaction data . Protocol Kit Relay Kit _ 13 import Safe, { OnchainAnalyticsProps } from '@safe-global/protocol-kit' _ 13 _ 13 const onchainAnalytics: OnchainAnalyticsProps = { _ 13 project: 'YOUR_PROJECT_NAME' // Required. Always use the same value for your project. _ 13 platform: 'CURRENT_PLATFORM' // Optional _ 13 } _ 13 _ 13 const protocolKit = await Safe.init({ _ 13 // ... _ 13 onchainAnalytics _ 13 }) _ 13 _ 13 // Execute the deployment Track Safe transactions Safe transactions can be tracked by concatenating the on-chain identifier at the end of the transaction data or user operation callData properties. This way Safe transactions will include the identifier. If you use the Protocol Kit or the Relay Kit to execute the Safe transactions, adding the onchainAnalytics property to the initialization method will automatically handle this. If you use a custom implementation, remember to manually add the on-chain identifier at the end of the transaction data / callData . Protocol Kit Relay Kit _ 13 import Safe, { OnchainAnalyticsProps } from '@safe-global/protocol-kit' _ 13 _ 13 const onchainAnalytics: OnchainAnalyticsProps = { _ 13 project: 'YOUR_PROJECT_NAME' _ 13 platform: 'CURRENT_PLATFORM' // Optional _ 13 } _ 13 _ 13 const protocolKit = await Safe.init({ _ 13 // ... _ 13 onchainAnalytics _ 13 }) _ 13 _ 13 // Execute the transaction Get the on-chain identifier If you use the Protocol Kit or the Relay Kit, call the getOnchainIdentifier method from an initialized instance of the Protocol Kit to get the current Safe on-chain identifier. _ 10 const onchainIdentifier = protocolKit.getOnchainIdentifier() Submission Form You can fill out the form by clicking this link (opens in a new tab) or using the form below: Loading… Web3Auth Onramp Was this page helpful? Report issue
프로젝트로 돌아가기