@ Override public Response init ( ChaincodeStub stub ) { try { // Get the args from the transaction proposal List < String > args = stub . getParameters ( ) ; if ( args . size ( ) != 2 ) { newErrorResponse ( "Incorrect arguments. Expecting a key and a value" ) ; } // Set up any variables or assets here by calling stub.putState() // We store the key and the value on the ledger stub . putStringState ( args . get ( 0 ) , args . get ( 1 ) ) ; return newSuccessResponse ( ) ; } catch ( Throwable e ) { return newErrorResponse ( "Failed to create asset" ) ; } }
Init is called during chaincode instantiation to initialize any data . Note that chaincode upgrade also calls this function to reset or to migrate data .