[SOLVED] Sending bnb to a specific address

i want to develop a contract where. when the function Optimizer is called it will send a specific amount of bnb to a specific wallet address, problem is the wallet address is not receiving the amount when i call the optimizer function.

** i am using bsc testnet and metamask.

pragma solidity ^0.8.7;

// SPDX-License-Identifier: GPL-3.0

contract AB {

   address payable  b= payable(0x9997aBff396d699FBFCEcbC17d69Bbe9343bD13e);

function Optimizer( )public  payable{

        msg.value==1000000000000000000 wei;

        require(msg.value==1000000000000000000 wei);


      b.transfer(msg.value);

    }

   }

When you call the optimizer function the transaction succeeds? You can also post on our Discord server in the #smart-contract-help channel

no metamask show this error: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error. { “code”: -32000, “message”: "execution reverted

You are sending this exact value with the transaction?

this is the value: i am only calling the function,metamask should transfer 1 bnb, right? while i am calling the optimizer function.

metamask should transfer 1 bnb, right?

How do you call this contract function? You need to specify the value to pass along with the transaction.

i am using metamask and the contract is in bsc testnet

this looks like invalid syntax for me

you can try it in remix until you make it work, you can also try to debug it in remix

i used 1 ether/ 1*1e18 also. and there is no error on remix, now?

does it work now in remix to call that Optimizer function and does it make that transfer?

it work on remix with 100000000000000000 wei as the value u set on remix differently. but when the contract is deployed then there is no remix option, hence the problem stand. metamask shows error with 1 ether also. the main goal is to call the function and pay the 1 bnb from my metamask.

there shouldn’t be an issue related to metamask if it works in remix

what do you mean with this part?

first of all metamask shows this error:Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error. { “code”: -32000, “message”: "execution reverted

and in remix i select value from here( 1 ether) remix

**is there any chance that you run it on remix by yourself and use bsc testnet with metamask?

You could deploy from Remix on bsc testnet with MetaMask as web3 injected and then you can run functions directly on the contract form bsc testnet from remix

i know all these steps, it looks like we are in a loop.so wha’st your opinion about metamask error?

i said this coz then you will know that the error exists.

That is an error for when the execution will be reverted.
I don’t know exactly how you call that contract function. You can not call it directly from MetaMask.

here what i do: i deploy the contract on bsc test net. then i call the function from remix, then i got the error on metamask( as my wallet is metamask)
to make it more clear to you: remix vm shows no error .

Then it means that it doesn’t work.
If you deploy on remix and test it on remix then it works?

yes in local environment it works if i assign value from remix ( mentioned in the pic i attached). but when i deploy on testnet with injected provider and call the function, metamask shows the error.