How to fix: Warning! Error encountered during contract execution [Bad instruction]

in #sparkster5 years ago

It has come to our attention that some people are receiving the following error after calling the swapTokens function: Warning! Error encountered during contract execution [Bad instruction]

This error occurs if you have approved more tokens in the 'increaseApproval' function than you actually hold in your wallet. Even If the approved quantity is slightly more than the number of tokens you own, the function will throw an error, by design, to prevent you from receiving more tokens than you own.

You can easily correct the problem, by transferring your tokens to a new wallet, and following the previous token swap guidelines very carefully.

Alternatively, if you do not wish to transfer the tokens, please follow the steps below. The steps below will also help you understand why the error occurred.

Step 1: Validate the number of tokens you have authorized to transfer.

Visit: https://etherscan.io/token/0x971d048e737619884f2df75e31c7eb6412392328#readContract

Scroll down to very bottom, to item number ‘20: allowance.’

In the ‘_owner (address)’ field, enter your wallet address where you hold SPRK.

In the ‘_spender (address)’ field, enter the address of the new contract: 0x80a740c8ffa28c8c2c3f1fc8b6c1a0a442212e71

Then click ‘Query’


(The example wallet used in this guide was provided to our support team and belongs to a token holder, this wallet is only being used for demonstration purposes).

Step 2: Validate the quantity from Step 1 is less than or equal to the number of tokens in your wallet.

Copy the quantity from above.

Go to: https://etherconverter.online/

Paste the value into the ‘Wei’ field, and note down the quantity in the ‘Ether’ field.

Now go to your wallet, and validate the quantity of tokens you hold is either equal to, or less than the quantity in the ‘Ether’ field.

The example wallet holds 4077.78 SPRK tokens. Because the quantity that has been approved to transfer via the ’increaseAllowance’ function (4078 in the example above) is greater than the quantity of tokens held in the wallet (4077.78 in this example), the function has retuned an error, by design, even if it is only slightly more.

If the authorized quantity from step 1 is greater than the quantity of tokens you hold, continue to step 3 to correct this.

Step 3: Set the approved quantity to zero.

Instructions for MyEtherWallet are below, for MetaMask scroll down.

After you have accessed your wallet via MEW, click on ’Contract’, then ‘Interact with Contract’ from the left hand menu.

In the ‘Contract Address’ field, enter: 0x971d048e737619884f2df75e31c7eb6412392328

In the ‘ABI/JSON Interface’ box, enter:

[{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]



Then click ‘Continue’

On the next screen, select ‘approve’ from the dropdown menu.

In the ‘_spender (address)’ field, enter: 0x80a740c8ffa28c8c2c3f1fc8b6c1a0a442212e71

In the ‘_value (uint 256)’ field, enter: 0

Leave the ‘Value in ETH’ set to 0

Then click ‘Write’ and complete the transaction as you have in the past.

Once the transaction has been confirmed, your approved number of tokens to transfer will have been reset to zero. Go back to the previous set of instructions, and carefully enter the correct amount in Step 1, ensuring the quantity being provided to the ’increaseApproval’ function is less than or equal to the exact number of tokens you hold in your wallet.

The instructions for MEW can be found here: https://steemit.com/sparkster/@sparkster/sprk-token-swap-procedure-for-myetherwallet

Instructions for MetaMask:

i. Navigate to: https://etherscan.io/token/0x971d048e737619884f2df75e31c7eb6412392328#writeContract

ii. Click ‘Connect to Web3’ next to the red dot, and authorize MetaMask to interact with our contract via etherscan. The red dot will turn green once approved.

iii. Scroll down to section '2. approve'.

Next,

In the ‘_spender (address)’ field, enter: 0x80a740c8ffa28c8c2c3f1fc8b6c1a0a442212e71

In the ‘_value (uint 256)’ field, enter: 0

Then click the ‘Write’ button

In the MetaMask window that appears, click ‘Confirm’

Once the transaction has been confirmed, your approved number of tokens to transfer will have been reset to zero. Go back to the previous set of instructions, and carefully enter the correct amount in Step 1, ensuring the quantity being provided to the ’increaseApproval’ function is less than or equal the exact number of tokens you hold in your wallet.

The instructions for MetaMask can be found here:
https://steemit.com/sparkster/@sparkster/sprk-token-swap-procedure-for-metamask