FundingΒΆ

To fund a channel means to send funds to the AssetHolder contracts corresponding to the channel assets. A channel always needs to be funded before it can be opened. The amount that needs to be deposited is agreed upon by both participants.

go-perun needs a Funder to fund a channel. Creating a Funder looks like this:

func setupFunder(contractBackend ethchannel.ContractBackend, account accounts.Account, assetHolder common.Address) channel.Funder {
	ethDepositor := new(ethchannel.ETHDepositor)
	accounts := map[ethchannel.Asset]accounts.Account{ethwallet.Address(assetHolder): account}
	depositors := map[ethchannel.Asset]ethchannel.Depositor{ethwallet.Address(assetHolder): ethDepositor}
	return ethchannel.NewFunder(contractBackend, accounts, depositors)
}

As you can see we use an ETHDepositor which means that the channel will only be funded with Ether. There is an equivalent ERC20Depositor if you need ERC20 Tokens. This function looks complicated since go-perun supports multi-asset channels. In the multi-asset case, you can add more than one AssetHolder to the Accounts and Depositors maps.