How to use @ethersproject/abstract-signer - 9 common examples

To help you get started, we’ve selected a few @ethersproject/abstract-signer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethers-io / ethers.js / packages / contracts / lib / index.js View on Github external
bytecodeHex = bytecode.object;
        }
        else {
            // Crash in the next verification step
            bytecodeHex = "!";
        }
        // Make sure it is 0x prefixed
        if (bytecodeHex.substring(0, 2) !== "0x") {
            bytecodeHex = "0x" + bytecodeHex;
        }
        // Make sure the final result is valid bytecode
        if (!bytes_1.isHexString(bytecodeHex) || (bytecodeHex.length % 2)) {
            logger.throwArgumentError("invalid bytecode", "bytecode", bytecode);
        }
        // If we have a signer, make sure it is valid
        if (signer && !abstract_signer_1.Signer.isSigner(signer)) {
            logger.throwArgumentError("invalid signer", "signer", signer);
        }
        properties_1.defineReadOnly(this, "bytecode", bytecodeHex);
        properties_1.defineReadOnly(this, "interface", properties_1.getStatic((_newTarget), "getInterface")(contractInterface));
        properties_1.defineReadOnly(this, "signer", signer || null);
    }
    ContractFactory.prototype.getDeployTransaction = function () {
github ethers-io / ethers.js / packages / contracts / lib / index.js View on Github external
function Contract(addressOrName, contractInterface, signerOrProvider) {
        var _newTarget = this.constructor;
        var _this = this;
        logger.checkNew(_newTarget, Contract);
        // @TODO: Maybe still check the addressOrName looks like a valid address or name?
        //address = getAddress(address);
        properties_1.defineReadOnly(this, "interface", properties_1.getStatic((_newTarget), "getInterface")(contractInterface));
        if (abstract_signer_1.Signer.isSigner(signerOrProvider)) {
            properties_1.defineReadOnly(this, "provider", signerOrProvider.provider || null);
            properties_1.defineReadOnly(this, "signer", signerOrProvider);
        }
        else if (abstract_provider_1.Provider.isProvider(signerOrProvider)) {
            properties_1.defineReadOnly(this, "provider", signerOrProvider);
            properties_1.defineReadOnly(this, "signer", null);
        }
        else {
            logger.throwArgumentError("invalid signer or provider", "signerOrProvider", signerOrProvider);
        }
        properties_1.defineReadOnly(this, "callStatic", {});
        properties_1.defineReadOnly(this, "estimate", {});
        properties_1.defineReadOnly(this, "functions", {});
        properties_1.defineReadOnly(this, "populateTransaction", {});
        properties_1.defineReadOnly(this, "filters", {});
        {
github ethers-io / ethers.js / packages / providers / lib / json-rpc-provider.js View on Github external
JsonRpcSigner.prototype.signMessage = function (message) {
        var _this = this;
        var data = ((typeof (message) === "string") ? strings_1.toUtf8Bytes(message) : message);
        return this.getAddress().then(function (address) {
            // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
            return _this.provider.send("eth_sign", [address.toLowerCase(), bytes_1.hexlify(data)]);
        });
    };
    JsonRpcSigner.prototype.unlock = function (password) {
        var provider = this.provider;
        return this.getAddress().then(function (address) {
            return provider.send("personal_unlockAccount", [address.toLowerCase(), password, null]);
        });
    };
    return JsonRpcSigner;
}(abstract_signer_1.Signer));
exports.JsonRpcSigner = JsonRpcSigner;
var UncheckedJsonRpcSigner = /** @class */ (function (_super) {
    __extends(UncheckedJsonRpcSigner, _super);
    function UncheckedJsonRpcSigner() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    UncheckedJsonRpcSigner.prototype.sendTransaction = function (transaction) {
        var _this = this;
        return this.sendUncheckedTransaction(transaction).then(function (hash) {
            return {
                hash: hash,
                nonce: null,
                gasLimit: null,
                gasPrice: null,
                data: null,
                value: null,
github ethers-io / ethers.js / packages / contracts / lib.esm / index.js View on Github external
bytecodeHex = bytecode.object;
        }
        else {
            // Crash in the next verification step
            bytecodeHex = "!";
        }
        // Make sure it is 0x prefixed
        if (bytecodeHex.substring(0, 2) !== "0x") {
            bytecodeHex = "0x" + bytecodeHex;
        }
        // Make sure the final result is valid bytecode
        if (!isHexString(bytecodeHex) || (bytecodeHex.length % 2)) {
            logger.throwArgumentError("invalid bytecode", "bytecode", bytecode);
        }
        // If we have a signer, make sure it is valid
        if (signer && !Signer.isSigner(signer)) {
            logger.throwArgumentError("invalid signer", "signer", signer);
        }
        defineReadOnly(this, "bytecode", bytecodeHex);
        defineReadOnly(this, "interface", getStatic((new.target), "getInterface")(contractInterface));
        defineReadOnly(this, "signer", signer || null);
    }
    getDeployTransaction(...args) {
github ethers-io / ethers.js / packages / contracts / lib.esm / index.js View on Github external
constructor(addressOrName, contractInterface, signerOrProvider) {
        logger.checkNew(new.target, Contract);
        // @TODO: Maybe still check the addressOrName looks like a valid address or name?
        //address = getAddress(address);
        defineReadOnly(this, "interface", getStatic((new.target), "getInterface")(contractInterface));
        if (Signer.isSigner(signerOrProvider)) {
            defineReadOnly(this, "provider", signerOrProvider.provider || null);
            defineReadOnly(this, "signer", signerOrProvider);
        }
        else if (Provider.isProvider(signerOrProvider)) {
            defineReadOnly(this, "provider", signerOrProvider);
            defineReadOnly(this, "signer", null);
        }
        else {
            logger.throwArgumentError("invalid signer or provider", "signerOrProvider", signerOrProvider);
        }
        defineReadOnly(this, "callStatic", {});
        defineReadOnly(this, "estimate", {});
        defineReadOnly(this, "functions", {});
        defineReadOnly(this, "populateTransaction", {});
        defineReadOnly(this, "filters", {});
        {
github ethers-io / ethers.js / packages / contracts / lib.esm / index.js View on Github external
connect(signerOrProvider) {
        if (typeof (signerOrProvider) === "string") {
            signerOrProvider = new VoidSigner(signerOrProvider, this.provider);
        }
        let contract = new (this.constructor)(this.address, this.interface, signerOrProvider);
        if (this.deployTransaction) {
            defineReadOnly(contract, "deployTransaction", this.deployTransaction);
        }
        return contract;
    }
    // Re-attach to a different on-chain instance of this contract
github ethers-io / ethers.js / packages / contracts / lib / index.js View on Github external
Contract.prototype.connect = function (signerOrProvider) {
        if (typeof (signerOrProvider) === "string") {
            signerOrProvider = new abstract_signer_1.VoidSigner(signerOrProvider, this.provider);
        }
        var contract = new (this.constructor)(this.address, this.interface, signerOrProvider);
        if (this.deployTransaction) {
            properties_1.defineReadOnly(contract, "deployTransaction", this.deployTransaction);
        }
        return contract;
    };
    // Re-attach to a different on-chain instance of this contract
github ethers-io / ethers.js / packages / ethers / lib / ethers.js View on Github external
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var contracts_1 = require("@ethersproject/contracts");
exports.Contract = contracts_1.Contract;
exports.ContractFactory = contracts_1.ContractFactory;
var bignumber_1 = require("@ethersproject/bignumber");
exports.BigNumber = bignumber_1.BigNumber;
exports.FixedNumber = bignumber_1.FixedNumber;
var abstract_signer_1 = require("@ethersproject/abstract-signer");
exports.Signer = abstract_signer_1.Signer;
exports.VoidSigner = abstract_signer_1.VoidSigner;
var wallet_1 = require("@ethersproject/wallet");
exports.Wallet = wallet_1.Wallet;
var constants = __importStar(require("@ethersproject/constants"));
exports.constants = constants;
var providers = __importStar(require("@ethersproject/providers"));
exports.providers = providers;
var providers_1 = require("@ethersproject/providers");
exports.getDefaultProvider = providers_1.getDefaultProvider;
var wordlists_1 = require("@ethersproject/wordlists");
exports.Wordlist = wordlists_1.Wordlist;
exports.wordlists = wordlists_1.wordlists;
var utils = __importStar(require("./utils"));
exports.utils = utils;
var logger_1 = require("@ethersproject/logger");
var errors = logger_1.Logger.errors;
github ethers-io / ethers.js / packages / wallet / index.js View on Github external
var mnemonic = hdnode_1.entropyToMnemonic(entropy, options.locale);
        return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
    };
    Wallet.fromEncryptedJson = function (json, password, progressCallback) {
        return json_wallets_1.decryptJsonWallet(json, password, progressCallback).then(function (account) {
            return new Wallet(account);
        });
    };
    Wallet.fromMnemonic = function (mnemonic, path, wordlist) {
        if (!path) {
            path = hdnode_1.defaultPath;
        }
        return new Wallet(hdnode_1.HDNode.fromMnemonic(mnemonic, null, wordlist).derivePath(path));
    };
    return Wallet;
}(abstract_signer_1.Signer));
exports.Wallet = Wallet;
function verifyMessage(message, signature) {
    return transactions_1.recoverAddress(hash_1.hashMessage(message), signature);
}
exports.verifyMessage = verifyMessage;

@ethersproject/abstract-signer

An Abstract Class for desribing an Ethereum Signer for ethers.

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis