URI Scheme with Metadata, Value and Bytecode

Description:
I’m trying to create a “Deep Link” for MetaMask to scan and initiate a contract call,
I tried the standard formats:

ERC-681

ethereum:0x1234...6789@137/FunctionFooName?&bytes32=01234...6789&uint256=13

Both can initiate a send transaction but the actual function is not called. Is the format of my call wrong? Or is MetaMask that has not the 681 implementation for the calldata? Thank you.

Hi @puddi , welcome to MetaMask community!

Have you checked MetaMask Docs and github repository for a solution?

https://docs.metamask.io/

1 Like

@puddi it should be working this feature was merged long time ago could you please have a look at this old closed issue: EIP-681 deeplink for ERC-20 function "approve" does not work in MetaMask mobile 1.05 · Issue #1980 · MetaMask/metamask-mobile · GitHub what function are you using, could you show your code pls

2 Likes

This is the function header

function BetGame(bytes32 gameId, bytes32 playerId) external payable minBet returns (bool) {
           ......
}

This is the Deep Link String

ethereum:0x4758aCF2d393A0f011C603eAfC9B4769322b2a94@43113/BetGame?bytes32=0x3863e63da67d85dcffede3cace2ebcbb39e67df5f6fdaf6437319cbe68cc3b94&bytes32=0x0fbf1ff35ca8785e1812f7745b1332b4b9b3c64ccd769f19869170beb4e4f513&value=1.0e15

Contract address is the correct, deployed on 43113 avalanche fuji testnet. The app is picking up the url but when sending the tx it has difficulties calculating the correct gas amount and gives JSON-RPC error.

thanks could you show the error message pls

2 Likes

The error message is very simple: Transaction error Internal JSON-RPC error. I tried changing also the RPC endpoint and I get the same error.

Im not sure how to see error logs / stack traces, but if you add the Fuji testnet network with some gas you can try the transaction, which it may possibly be an actual correct txn that goes through by scanning the QR (the data in the QR is the Deep Link String mentioned before):

download

Thanks I’ll try, I see the error thanks. Could you show me how you build this deeplink are you using MetaMask sdk?

Where this function coming from is it from sdk, thanks:

function BetGame(bytes32 gameId, bytes32 playerId) external payable minBet returns (bool) { ...... }

2 Likes

I’m working in java, and I’m using the zxing library. The QR code you see is generated in Brave Browser using “QR code ”. I did a quick look at the SDK, but I don’t see any methods to generate a EIP-681 QR or a more general string QR.

The function BetGame is a custom function of my contract, here’s the full implementation:

/**
     * BetGame accetps and registers a player's game bet
     */
    function BetGame(bytes32 gameId, bytes32 playerId) external payable minBet returns (bool) {
        address caller = _msgSender();
        uint256 betAmount = msg.value;

        // if firts game make him start it
        if (!getActiveGame(gameId)) {
            emit GameStarted(gameId, playerId, caller, betAmount, block.timestamp);
        }

        // Already in
        if (playerAddress[playerId] != address(0)) {
            revert BetAlreadyPlaced(caller, playerGameBalance[playerId][caller]);
        }

        gamePlayersIds[gameId].push(playerId);
        gameBalance[gameId] += betAmount;
        playerAddress[playerId] = caller;
        playerGameBalance[playerId][caller] = betAmount;
        emit PlayerBet(gameId, playerId, caller, betAmount, block.timestamp);
        return true;
    }

/**
     * getActiveGame reutrns true is a game is active
     */
    function getActiveGame(bytes32 gameId) public view returns (bool) {
        if (gamePlayersIds[gameId].length > 0) {
            return true;
        }

        return false;
    }

Hi could you please open a support ticket: https://support.metamask.io/hc/en-us/requests/new?ticket_form_id=15071540780827 I’m not sure if it’s zxing library or what we need to check further

2 Likes

Let’s keep the discussion open until we solve this, may be useful content for people searching about the topic in the future.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.