After the wallet is logged in, we can use the wallet to send transaction deployment contracts.
The web3 tool class also provides tool functions for deploying contracts web3.deploy()
. The contract instance and the amount of bitcoin locked by the contract are the parameters of this function. This function will do the following:
listUnspent
interface. Used to pay transaction fees and locked balances for deploying contracts.getSignature
interface of the wallet to request the wallet to sign the transaction.sendRawTransaction
interface of the wallet to broadcast the transaction.After the player fills in the amount of bitcoin locked in the contract and clicks the start button, the startGame
method in the App
component will be called back. This function implements the function of deploying a contract instance to the Bitcoin network. After successful deployment, save the UTXO containing the contract and the initial game state to localStorage , and update the React state.
const startGame = async (amount) => { if (web3.wallet && states.instance) { web3.deploy(states.instance, amount).then(rawTx => { ... }) } };
web3.deploy()
function in the startGame
function to deploy the contract. And after successful deployment save transaction to ContractUtxos
and update game state.Refer to this commit