Argent
Search…
Wallet Connect and Argent
How to make sure your Dapp works seamlessly with Argent!
WalletConnect is an open source protocol for connecting decentralized applications ("Dapps") to mobile wallets, via QR code scanning or deep linking. A user can interact securely with any Dapp from their mobile phone, making WalletConnect enabled wallets a safer choice compared to desktop or browser extension wallets.
As a mobile wallet, Argent fully supports the WalletConnect protocol. Since Argent is a smart contract based wallet, you need to pay attention to some specific features.

Message signature

Externally Owned Accounts (EOA) can sign messages with their associated private keys, however, smart contracts cannot. EIP-1271 outlines a standard way for contracts to verify if a provided signature is valid when an account is a contract.
The Argent wallet implements theisValidSignature() method, as per EIP-1271. A Dapp that wants to verify the signature of an Argent user should therefore call isValidSignature() on the Argent wallet instead of ecrecover() (as would be used to verify signatures from EOA accounts).
1
contract ERC1271 {
2
3
// bytes4(keccak256("isValidSignature(bytes32,bytes)")
4
bytes4 constant internal MAGICVALUE = 0x1626ba7e;
5
6
/**
7
* @dev Should return whether the signature provided is valid for the provided data
8
* @param _hash EIP-191 compliant hash of the message
9
* @param _signature Signature byte array associated with _data
10
*
11
* MUST return the bytes4 magic value 0x1626ba7e when function passes.
12
* MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5)
13
* MUST allow external calls
14
*/
15
function isValidSignature(
16
bytes32 _hash,
17
bytes memory _signature
18
)
19
public
20
view
21
returns (bytes4 magicValue);
22
}
Copied!
The parameter _hash should be EIP-191 compliant. See full example here in Javascript (using ethers.js library):
1
const argentABI = [
2
'function isValidSignature(bytes32 _message, bytes _signature) public view returns (bool)'
3
];
4
5
const walletAddress = "0x...";
6
const message = "Lorem ipsum dolor sit amet";
7
8
const argentWallet = new ethers.Contract(walletAddress, argentABI, provider);
9
const hashMessage = ethers.utils.hashMessage(message);
10
11
try {
12
const returnValue = await argentWallet.isValidSignature(hashMessage, signature)
13
} catch (error) {
14
// signature is not valid
15
}
16
Copied!

Wallet detection

We have developed and deployed a simple contract to detect if a given address corresponds to an Argent wallet. The contract exposes a single isArgentWallet(address) method that returns true if the code deployed at the input address matches a deployed version of the Argent wallet.
1
contract ArgentWalletDetector {
2
3
/**
4
* @notice Checks if an address is an Argent wallet
5
* @param _wallet The target wallet
6
*/
7
function isArgentWallet(
8
address _wallet
9
)
10
external
11
view
12
returns (bool);
13
}
Copied!
The detector contract is deployed on Ropsten testnet and Mainnet:
1
Ropsten: 0xF230cF8980BaDA094720C01308319eF192F0F311
2
Mainnet: 0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8
Copied!

Multicall

Argent wallets support the ability to batch transactions into a single transaction, for example an ERC20 approval followed by a contract call
1
const argentABI = [
2
"function isValidSignature(bytes32 _message, bytes _signature) public view returns (bool)",
3
"function wc_multiCall((address to, uint256 value, bytes data)[] _transactions)",
4
];
5
6
const walletAddress = "0x...";
7
8
const argentWallet = new ethers.Contract(walletAddress, argentABI, provider);
9
10
const result = await argentWallet.wc_multiCall(
11
[
12
// approve USDC
13
{
14
to: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
15
value: 0,
16
data: "0x095ea7b3000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff0000000000000000000000000000000000000000fffffffffff096fb4da20000",
17
},
18
// call contract
19
{
20
to: "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
21
value: 0,
22
data: "0x........",
23
},
24
]
25
);
Copied!
The best practice is to check if the wallet is an Argent wallet using the wallet detector contract and then batch the transactions:
1
const walletDetectorAddress = "0xeca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8";
2
const walletDetectorABI = [
3
"function isArgentWallet(address _wallet) external view returns (bool)"
4
];
5
6
const walletDetector = new ethers.Contract(walletDetectorAddress, walletDetectorABI, provider);
7
const isArgent = await walletDetector.isArgentWallet(address);
8
9
if (isArgent) {
10
// do a multicall
11
} else {
12
// do single calls
13
}
Copied!

Meta transactions and relayers

Argent wallet uses the concept of meta transactions. These are a particular type of transaction which are signed by one or more key pairs (in our case the wallet's owner and potentially their guardians) but are submitted to the Ethereum network by a relayer. The relayer pays the gas fee (in ETH) and the wallet will refund the relayer (in ETH or ERC20 tokens) up to an amount signed by the wallet's owner.
From a Dapp perspective, this is managed by the Argent mobile application. The Dapp will submit a regular { to, value, data } transaction to the web3 provider. This transaction will be transmitted to the Argent mobile application through Wallet Connect. The mobile wallet will transform the data into a meta transaction:
  • to will be the Argent RelayerManager contract address
  • data will be the encoded data of the call to the execute() method with the relevant parameters
The Dapp will receive the transaction hash in order to monitor the status of the transaction and events will be emitted as usual.
Our relayer has the ability to replay a transaction with a higher gas price due to fluctuating network conditions. The transaction hash is modified and the Dapp will not be aware of the new transaction hash.
One solution could be for the Dapp to observe a specific event being emitted instead of transaction status. We are working on defining a standard for a Dapp to be notified when a transaction is replaced and the transaction hash changes (contact us if you are interested in this).

Login UX best practice

To improve the login experience for Argent users, we recommend showing an Argent branded login button at the top level. This ensures people less familiar with WalletConnect can log in to your app. When clicking on the Argent login, you then present the WalletConnect QR code.
You can find an example of this implementation on https://app.flexa.network/connect

FAQ

Can I use the ERC20 permit function?

It depends on how the ERC20 smart contract implements the permit() method. If you look below (source Etherscan) at the Maker DAI implementation, you will notice at line 24 the use of ecrecover() and not EIP-1271 to verify the signature. Here, the call will fail with Argent wallets.
1
function permit(
2
address holder,
3
address spender,
4
uint256 nonce,
5
uint256 expiry,
6
bool allowed,
7
uint8 v,
8
bytes32 r,
9
bytes32 s
10
) external {
11
bytes32 digest =
12
keccak256(abi.encodePacked(
13
"\x19\x01",
14
DOMAIN_SEPARATOR,
15
keccak256(abi.encode(PERMIT_TYPEHASH,
16
holder,
17
spender,
18
nonce,
19
expiry,
20
allowed))
21
));
22
23
require(holder != address(0), "Dai/invalid-address-0");
24
require(holder == ecrecover(digest, v, r, s), "Dai/invalid-permit");
25
require(expiry == 0 || now <= expiry, "Dai/permit-expired");
26
require(nonce == nonces[holder]++, "Dai/invalid-nonce");
27
uint wad = allowed ? uint(-1) : 0;
28
allowance[holder][spender] = wad;
29
emit Approval(holder, spender, wad);
30
}
Copied!

I'm asking for ERC20 approval of an amount of
105310^{53}
but it doesn't seem to work

Argent may override the "infinite value" and ask a user to input a smaller amount due to the additional security risk of allowing large persistent approvals. When checking the allowance in your Dapp you need to check for the exact amount the user wants to spend.

Can I use 3rd party relayers with Argent

Yes, but the relayer needs to implement a call to the execute() method of our RelayerManager smart contract. You will have to get the wallet owner signing the correct payload which is not straightforward. Please contact us if you're interested in this topic.

Do you estimate gas?

Yes, we use eth_estimateGas before sending any transaction.
Yes, Wallet Connect will work on mobile browsers (or native mobile apps) and will deep link to the Argent wallet

How can I test the integration

You can test Argent on Ropsten on both iOS and Android. Contact [email protected] to receive a test build.
Last modified 3mo ago