如何从智能合同中提取以太坊

发布于 2025-01-22 12:01:02 字数 516 浏览 0 评论 0原文

我是区块链技术的新手,我有疑问。 我刚刚向Rinkeby TestNet网络部署了一份以太坊智能合约,并铸造了一些NFT。在rinkeby.etherscan.io上检查我的合同地址时,我可以看到智能合约的余额。

问题是,如何将这些以太坊在智能合同平衡中转移到我的钱包中。既然我是所有者,我应该以某种方式收到这些ETH,以某种方式进入我的MetAmask钱包?

智能合约包括以下功能

    // This will transfer the remaining contract balance to the owner.
    // Do not remove this otherwise you will not be able to withdraw the funds.
    (bool os, ) = payable(owner()).call{value: address(this).balance}('');
    require(os);
  }```

so it should be possible...

I am a newbie in the blockchain technology and I have question.
I just deployed an Ethereum smart contract to the Rinkeby testnet network and minted a few NFTs. When checking my contract address on rinkeby.etherscan.io I can see the smart contract's balance.

The question is, how can I transfer these ethereum in the smart contract balance to my wallet. Since I am the owner I should receive these ETH somehow to my metamask wallet no?

Smart contract includes the following function

    // This will transfer the remaining contract balance to the owner.
    // Do not remove this otherwise you will not be able to withdraw the funds.
    (bool os, ) = payable(owner()).call{value: address(this).balance}('');
    require(os);
  }```

so it should be possible...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤浅笑 2025-01-29 12:01:02

根据您当前的实施,您需要从所有者地址从合同中提取ETH时,从所有者地址手动调用fort()函数。

您的薄荷功能接受ETH并将其保留在合同地址上。

如果要将资金转移到所有者每次执行薄荷时,都需要明确调用每个薄荷功能的传输。例子:

function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
    require(!paused, 'The contract is paused!');

    _safeMint(_msgSender(), _mintAmount);

   // auto transfer received funds to the owner
   payable(owner()).transfer(msg.value);
}

Per your current implementation, you need to manually invoke the withdraw() function from the owner address each time you want to withdraw ETH from the contract.

Your mint functions accept ETH and keep it on the contract address.

If you want to transfer the funds to the owner each time a mint is performed, you need to explicitly invoke the transfer from each of the mint functions. Example:

function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
    require(!paused, 'The contract is paused!');

    _safeMint(_msgSender(), _mintAmount);

   // auto transfer received funds to the owner
   payable(owner()).transfer(msg.value);
}
梨涡 2025-01-29 12:01:02

要能够将资金从合同中提取到您拥有的钱包

 address public primary_wallet = YOUR_WALLET_ADDRESS
 
 function withdraw() public payable onlyOwner {
   (bool os,)= payable(primary_wallet).call{value:address(this).balance}("");
   require(os);
 }

中/access/ownable.sol“; 使用唯一的atherer修饰符。这只允许部署合同的人撤回资金,没有其他人。这是必须的。希望这会有所帮助。

To be able to withdraw the funds from your contract to a wallet you own you must implement a withdraw method like so:

 address public primary_wallet = YOUR_WALLET_ADDRESS
 
 function withdraw() public payable onlyOwner {
   (bool os,)= payable(primary_wallet).call{value:address(this).balance}("");
   require(os);
 }

You will also need to make sure that you import import "@openzeppelin/contracts/access/Ownable.sol"; to use the onlyOwner modifier. This allows only the person who deployed the contract to withdraw the funds and nobody else. This is a must. Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文