Ethers.js

Gnosis 安全轉移功能 Approve Hash 但不轉移 erc20 代幣

  • July 6, 2022

我在這裡使用 gnosis-safe 核心 SDK 來創建交易,以將 Eth 從部署的安全代理中轉移出去。文件:https ://github.com/safe-global/safe-core-sdk/tree/main/packages/safe-core-sdk#deploysafe

我通過以下方式在 Rinkeby 上部署了代理:

       const { ethereum } = window;
       const provider = new ethers.providers.Web3Provider(ethereum)
       const safeOwner = provider.getSigner(0)
       const ethAdapter = new EthersAdapter({ ethers, signer: safeOwner });

       const txServiceUrl = 'https://safe-transaction.gnosis.io';
       const safeService = new SafeServiceClient({ txServiceUrl, ethAdapter });
       const is_dev = true;
       let ethAdapter = this.ethAdapter;
       const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeMasterCopy: !is_dev });

       const safeAccountConfig = {
         owners: ['0x...D9'],
         threshold: 1,
       }        

       const safeSdk = await safeFactory.deploySafe({ safeAccountConfig });        

所以它是一個只有一個授權人的保險箱。然後我將一些 ETH 存入這個安全代理,並嘗試將其從保險箱中發送出去:

       let safeAddress = '0x...c';
       const safeSdk = await Safe.create({ ethAdapter, safeAddress, isL1SafeMasterCopy: false })
       const num_ethers = ethers.utils.parseUnits("0.1", 'ether').toHexString();
       const transaction = {
         to: '0x...1', 
         data: '0x',
         value:num_ethers,
       }
       const safeTransaction = await safeSdk.createTransaction(transaction)        
       console.log('safeTransaction: ', safeTransaction)
       const hash = await safeSdk.getTransactionHash(safeTransaction);
       const txResponse = await safeSdk.approveTransactionHash(hash);
       const reshash = await txResponse.transactionResponse?.wait();       

最終發生的是授權人為ApproveHash交易付費,但 Eth 沒有轉移。從概念上講,我在這裡缺少什麼嗎?數據欄位也應該0x用於在 Rinkeby 網路上傳輸 eth,對嗎?發送日誌在這裡:https ://rinkeby.etherscan.io/address/0x99Ae62C23728EAa970F5064DcD3F869ae80FC89c

approveTransactionHash只批准交易而不執行它。請參閱核心 SDK 文件以了解如何執行交易https://github.com/safe-global/safe-core-sdk/blob/main/packages/guides/integrating-the-safe-core-sdk。 md#8-執行交易

引用自:https://ethereum.stackexchange.com/questions/131256