The Brink SDK is a useful tool for developers who want to create and execute upon signed messages.
Installation
The Brink SDK module can be used to interact with Brink proxy accounts, either as the account owner/signer or as an executor of messages signed by the account owner/signer.
const ethers = require('ethers)
const brinkSDK = require('@brinkninja/sdk')
// Obtain a signer and a provider from the Ethers Library [link above]
const ethersProvider = await ethers.getDefaultProvider(process.env.RPC_URLS)
const ethersSigner = await new ethers.Wallet(process.env.ETH_PRIVATE_KEY)
// Instantiate with environment config: `local`, `dev`, `prod` (see brink-environment) [link above]
const brink = brinkSDK('dev')
// Get an Account instance for any account owner, to read account state and execute meta transactions for this account
// Requires: ownerAddress, provider
// Optional: signer (If not provided, uses provider.getSigner()[link above])
const account = brink.account(ownerAddress, { provider: ethersProvider, signer: ethersSigner })
// Get an AccountSigner instance to sign messages as the owner of an account. Takes an ethers.js Signer [link above]
const accountSigner = brink.accountSigner(ethersSigner)
Account
Read-only Methods
These methods are available to read from account contract state
Implementation()
Returns the implementation address of the account proxy contract. Should be a deployed instance of Account.sol.
The Account instance exposes the ethers.js write method analysis propertiesestimateGas, populateTransaction, and callStatic. These can be used for any Account transaction. For example, getting transaction data without submitting the transaction can be done like this:
And an example of getting a gas estimate is below:
All of these transactions (except for deploy()) will include the desired action after account deployment, if the account has not been deployed yet, using DeployAndExecute.sol. If the account is already deployed, the action will be executed directly on the account contract.
sendLimitSwap(limitSwapSignedMessage, to, data)
params:
limitSwapSignedMessage: a valid signed limit swap message (see AccountSigner methods signEthToTokenSwap(), signTokenToTokenSwap(), and signTokenToEthSwap())
to: Address of the contract that will provide liquidity for the fullfilment of the swap
data: Call data that will be executed on the contract at toAddress in order to fullfil the swap
Example:
deployment, if the account has not been deployed yet, using DeployAndExecute.sol. If the account is already deployed, the action will be executed directly on the account contract.
cancel(cancelSignedMessage)
params:
cancelSignedMessage: a valid signed cancel message (see AccountSigner method signCancel())
Example:
transferEth(signedEthTransferMessage)
params:
signedEthTransferMessage: a valid signed eth transfer message (see AccountSigner method signEthTransfer())
Example:
transferToken(signedTokenTransferMessage)
params:
signedTokenTransferMessage: a valid signed token transfer message (see AccountSigner method signTokenTransfer())
Example:
deploy()
Deploys the account contract. Throws an error if the contract is already deployed
{
message: '<signed message hash>',
EIP712TypedData: <object with decoded EIP712 typed data>,
signature: '<the signature>',
signer: '<address of the signer>',
accountAddress: '<address of the account>',
functionName: '<function on Account.sol that is authorized by this message>',
signedParams: <array of signed parameters>
}