const{ zecrey }=window;// global window in browserif(zecrey){constaccounts: string[]=awaitzecrey.request({method: "eth_requestAccounts",});returnaccounts[0];}else{alert("Please install Zecrey.");}
NEAR
const{ zecrey }=window;// global window in browserif(zecrey){constaccounts: string[]=awaitzecrey.request({method: "near_requestAccounts",});returnaccounts[0];}else{alert("Please install Zecrey.");}
Zecrey L2
const{ zecrey }=window;// global window in browserif(zecrey){constaccounts: string[]=awaitzecrey.request({method: "zecrey_requestAccounts",});returnaccounts[0];}else{alert("Please install Zecrey.");}
2. Transfer native token on L1
EVM
const{ zecrey }=window;// global window in browser// Switch chain.zecrey.request({method: "wallet_switchEthereumChain",params: [{chainId: "0x4"}],}).then(console.log);// Check current chain IDconstchainId=awaitzecrey.send("eth_chainId");consttransactionParameters={from: selectedAddress,to: "0x0000000000000000000000000000000000000000",value: "0x2540be400",gasPrice: "0x09184e72a000",gas: "0x2710",chainId: "0x4",};consttxHash=awaitzecrey.request({method: "eth_sendTransaction",params: [transactionParameters],});
NEAR
const{ zecrey }=window;// global window in browserconsttransactionParameters={sender: nearAccountId,receiver: "example.testnet",action: "transfer",args: ["0x2540be400"],};consttxHash=awaitzecrey.request({method: "near_sendTransaction",params: transactionParameters,});
3. Call method of a smart contract on L1
EVM
const{ zecrey }=window;// global window in browser// Switch chain.zecrey.request({method: "wallet_switchEthereumChain",params: [{chainId: "0x4"}],}).then(console.log);// Check current chain IDconstchainId=awaitzecrey.send("eth_chainId");// Interact with an ERC20 contract to transfer some token.consttransactionParameters={from: selectedAddress,to: contractAddress,value: "",data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057",gasPrice: "0x09184e72a000",gas: "0x2540be4",chainId: "0x4",};consttxHash=awaitzecrey.request({method: "eth_sendTransaction",params: [transactionParameters],});
NEAR
const{ zecrey }=window;// global window in browser// Interact with an FT contract to transfer some token.consttransactionParameters={sender: nearAccountId,receiver: contract,action: "functionCall",args: ["ft_transfer",{receiver_id: "example.testnet",amount: "0x2540be400000000",},"300000000000000",// gas"1",// deposit],};consttxHash=awaitzecrey.request({method: "near_sendTransaction",params: transactionParameters,});
const{ zecrey }=window;// global window in browserconstfrom='0xD9ec5DAABd83dD452445f4bCA909aaeA335A9F38';constmessage='hello world';constsigned=awaitzecrey.request({methode: 'eth_sign',params: [from,message],
from
})// 0x4734cbab803486d493073000edf7fa71e5778591f08eb02b8f7ae60ac1e1c64c725671ec88183c4d8db486255699265a7b77a3964571214608da0db716b52c7a1c