- Create a simple multiSig contract.
- Deploy the contract on the Fuse Spark testnet through a Fuse node.
- Interact with the deployed contract.
Prerequisites
- A public Fuse endpoint.
- Hardhat to compile and deploy the contract.
- Hardhat ABI Exporter to export the ABI to interact with the contract.
- MetaMask to interact with the contract through your Chainstack node.
Get your Fuse node endpoint
For example, get a community public endpoint.Install Hardhat
See Hardhat documentation.Initialize a Hardhat project
In your project directory, runnpx hardhat. Select Create a JavaScript project.
Create and compile the multiSig contract
In thecontracts directory, create multiSig.sol.
- The addresses that the deployer passes as parameters are set as co-owners of the multiSig Wallet. Along with that, the deployer passes an integer as the parameter. This integer will be the minimum number of confirmations a transaction will require to be approved. This integer must be greater than zero and must be less than or equal to the number of co-owners of the contract.
receiveis a special function provided by Solidity that allows the contract to accept protocol native tokens without a specially defined function. It is declared without the keywordfunctionand must be external and payable.- After declaring a struct to store the transaction data, there are two mappings to store the validity of the contract owners and to store all confirmations to a particular transaction.
- The functions defined mostly restrict access to the owners, even though anyone can read the data. The function
executeTransactionuses the low-level methodcall()to transfer the protocol native tokens from the contract to the required address if the transaction is approved.
npx hardhat compile.
Fund your account
Fund the account that you will use to deploy the contract with SPARK—the native token of the Fuse Spark testnet. Use the Fuse Spark testnet faucet.Set up Hardhat to work through your Fuse node
In your project directory, open for editinghardhat.config.js.
- YOUR_NODE_ENDPOINT — your Fuse node HTTPS endpoint. See also Fuse tooling.
- YOUR_PRIVATE_KEY — the private key of your Fuse account that will deploy the contract. The account must have enough funds to run the deployment. See also Fuse Spark testnet faucet.
Deploy the multiSig contract
Set up the deployment script atscripts/deploy.js.
- OWNER — the addresses that co-own the contract and whose confirmations are required to withdraw the funds.
- CONFIRMATION_NUMBER — the number of confirmations required by the contract owners to withdraw the funds.
0x7B397Bd7042560cdaE08C674Ef554e5C3239bC10 and 0xFDa85C3404dC00fFBe2A18615ba55380cB42c8Fb and that requires a confirmation from both owners (2):
Interact with the contract
Once your contract is deployed, you can view it online at Fuse Spark testnet explorer. You are now going to verify the contract in the explorer to be able to use the explorer as a web app and easily interact with the contract online.Verify the deployed contract on the explorer
Go to Fuse Spark testnet explorer.
Find your deployed contract. The address of your contract is printed in the terminal by Hardhat at the end of the deployment.
In Compiler, select the same compiler version that was used in the Hardhat configuration file. In our example, it is
v0.8.10.In ABI-encoded Constructor Arguments, provide constructor values:
-
Copy the ugly ABI version from your project directory. For this example, it is
abi/ugly/contracts/multiSig.sol/multiSigWallet.json. - Go to Online ABI Encoding Service.
- Enter your ABI and click Parse.
-
Enter the contructor parameters that you provided in your deployment script in
deploy.js. - Copy the resulting value and put it in the ABI-encoded Constructor Arguments field in the explorer.
Interact with the contract
Set up your MetaMask instance to work through your Fuse node. See Fuse tooling: MetaMask. Using MetaMask, send some funds to the contract. Now that your multiSig contract is verified, you can use the explorer to interact with it.- In the explorer, on your contract, click Write Contract.
- In your MetaMask, make sure you have the same address selected as the one that one of the contract owners.
- Click Connect wallet. This will connect your MetaMask instance with the contract owner as the active address.
- In submitTransaction, provide an address to send some funds to and the amount of funds in Wei. You can also use the online unit converter.
- Click Write.
- Once the transaction is included in a block, confirm it by providing the transaction index in confirmTransaction and clicking Write. Since this is the first transaction on the contract, the index is
0. - Connect to the contract on the explorer with the other account that you provided as owner when deploying the contract.
- Again, confirm the transaction through confirmTransaction and the index
0. - Once the confirmation transaction is included in a block, execute it through executeTransaction and the index
0.
