Set Developer Fee

Charge a fee per transaction.


Developers are able to take a fee from every FunWallet transaction as:

  • A percentage of the gas spent in the transaction.

  • An absolute amount of tokens.



Minimal custom logic also enables fees to be taken as:

  • A percentage of transaction volume in the transaction.

  • A percentage of transaction volume with a cap.



The options.fee entry is required to be specified for a developer to take a fee. The parameters of this object are:

const options = {
apiKey: API_KEY,
fee: {
token: "usdc", // The name of the token to receive the fee in (e.g. `"ETH"`).
gasPercent: 4, // The amount of fee to take, either as an absolute value or as a percentage of gas. (could also be amount)
recipient: "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9" // The address of the recipient of the fee
}
}

If token is left blank, the denomination of the fee to take will default to the token used to pay gas.


Charge a gas-variable transaction fee

The below code sets the developer fee as a percentage of the gas spent in the transaction, to be collected in the native gas token of the network.

const options = {
fee: {
token: "eth", // gas token, ie ETH
gasPercent: 4, // 4% of the transaction amount, capped at 100
recipient: "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"
}
}
,
variable-gas-fee.js
const ethers = require("ethers")
const { FunWallet, configureEnvironment } = require("fun-wallet")
const { Eoa } = require("fun-wallet/auth")
const { fundWallet } = require("fun-wallet/utils")
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"
const DEST_ADDR = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
async function configureGas() {
await configureEnvironment({
apiKey: API_KEY,
fee: {
token: "0x0000000000000000000000000000000000000000", // gas token, ie ETH
gasPercent: 4, // 4% of the transaction amount, capped at 100
recipient: "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"
}
})
const auth = new Eoa({ privateKey: PRIVATE_KEY })
const uniqueId = auth.getUniqueId()
const funWallet = new FunWallet( { uniqueId } )
// NOTE: Wallet must be prefunded if not using a sponsor
// await fundWallet(funder_auth, wallet, .005)
const receipt = await funWallet.transfer(auth, {
to: DEST_ADD,
amount: 10,
token: "USDC"
})
}
configureGas()

Charge a fixed transaction fee

The below code sets the developer fee to be a fixed amount per transaction, to be collected in USDC.

const options = {
fee: {
token: "usdc",
amount: 1, // 1 USDC
recipient: "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"
}
}
,
fixed-gas-fee.js
const ethers = require("ethers")
const { FunWallet, configureEnvironment } = require("fun-wallet")
const { Eoa } = require("fun-wallet/auth")
const { fundWallet } = require("fun-wallet/utils")
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"
const DEST_ADDR = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
async function configureGas() {
await configureEnvironment({
apiKey: API_KEY,
fee: {
token: "usdc",
amount: 1, // 1 USDC
recipient: "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"
}
})
const auth = new Eoa({ privateKey: PRIVATE_KEY })
const uniqueId = auth.getUniqueId()
const funWallet = new FunWallet( { uniqueId } )
// NOTE: Wallet must be prefunded if not using a sponsor
// await fundWallet(funder_auth, wallet, .005)
const receipt = await funWallet.transfer(auth, {
to: DEST_ADD,
amount: 10,
token: "USDC"
})
}
configureGas()

Charge a variable fee based on transaction volume

The below code is custom option parameters to be implemented on a per transaction basis.

// Charge a 1% fee on each transaction based on volume
const transactionFee = transactionAmount*0.01
fee: {
token: "usdc",
amount: transactionFee,
recipient: DEVELOPER_ADDR
}
,
variable-transaction-fee.js
const ethers = require("ethers")
const { FunWallet, configureEnvironment } = require("fun-wallet")
const { Eoa } = require("fun-wallet/auth")
const { fundWallet } = require("fun-wallet/utils")
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"
const DEST_ADDR = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
const DEVELOPER_ADDR = "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"
async function configureGas() {
await configureEnvironment({
apiKey: API_KEY,
})
const auth = new Eoa({ privateKey: PRIVATE_KEY })
const uniqueId = auth.getUniqueId()
const funWallet = new FunWallet( { uniqueId } )
// NOTE: Wallet must be prefunded if not using a sponsor
// await fundWallet(funder_auth, wallet, .005)
const transactionAmount = 10
// Charge a 1% fee on each transaction
const transactionFee = transactionAmount*0.01
// Add custom environment options to this transaction
const receipt = await funWallet.transfer(auth, {
to: DEST_ADD,
amount: transactionAmount,
token: "USDC"
}, {
fee: {
token: "usdc",
amount: transactionFee,
recipient: DEVELOPER_ADDR
}
})
}
configureGas()