Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An example how to use this library with viem.sh would be great. #280

Open
johanneskares opened this issue Jun 20, 2023 · 1 comment
Open

Comments

@johanneskares
Copy link

The new kid on the block is viem.sh

It would be great to see an example with this library.

@johanneskares johanneskares changed the title An example to use with viem.sh would be great. An example how to use this library with viem.sh would be great. Jun 20, 2023
@johanneskares
Copy link
Author

Here's how I solved it at the end:

import { DefenderRelayProvider } from "defender-relay-client/lib/web3";

const openZeppelinDefenderCredentials = {
  apiKey: process.env.OPENZEPPELIN_DEFENDER_API_KEY ?? "",
  apiSecret: process.env.OPENZEPPELIN_DEFENDER_SECRET ?? "",
};

const web3 = new DefenderRelayProvider(openZeppelinDefenderCredentials, {
  speed: "fast",
});

const client = createWalletClient({
  account: "0x79e084564564b4808559b17a9f6062342340", //  Your Defender Address goes here
  chain: getChain(),
  transport: custom({
    async request({ method, params }) {
      return await new Promise(function (resolve, reject) {
        web3.send({ method, params, jsonrpc: "2.0" }, (error, result) => {
          console.log("result", method, params, error, result);
          if (error != null || result?.error != null || result == null) {
            reject(error);
          } else {
            resolve(result.result);
          }
        });
      });
    },
  }),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant